Skip to content

Commit 9f77d5f

Browse files
bugfix(@nestjs/common) revert @catch() validation
1 parent d92fa0d commit 9f77d5f

4 files changed

Lines changed: 28 additions & 49 deletions

File tree

packages/common/decorators/core/catch.decorator.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import 'reflect-metadata';
22
import { FILTER_CATCH_EXCEPTIONS } from '../../constants';
33
import { Type } from '../../interfaces';
4-
import { isNil } from '../../utils/shared.utils';
5-
import { InvalidDecoratorItemException } from '../../utils/validate-each.util';
64

75
/**
86
* Defines the Exceptions Filter. Takes set of exception types as an argument which has to be caught by this Filter.
97
* The class should implement the `ExceptionFilter` interface.
108
*/
119
export function Catch(...exceptions: Type<any>[]): ClassDecorator {
12-
const validateNil = item => {
13-
if (isNil(item)) {
14-
throw new InvalidDecoratorItemException('@Catch', `value (${item})`, 'runtime exception');
15-
}
16-
};
17-
exceptions.forEach(validateNil);
1810
return (target: object) => {
1911
Reflect.defineMetadata(FILTER_CATCH_EXCEPTIONS, exceptions, target);
2012
};

packages/common/test/decorators/catch.decorator.spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect } from 'chai';
22
import 'reflect-metadata';
33
import { FILTER_CATCH_EXCEPTIONS } from '../../constants';
44
import { Catch } from '../../decorators/core/catch.decorator';
5-
import { InvalidDecoratorItemException } from '../../utils/validate-each.util';
65

76
describe('@Catch', () => {
87
const exceptions: any = ['exception', 'exception2'];
@@ -14,15 +13,4 @@ describe('@Catch', () => {
1413
const metadata = Reflect.getMetadata(FILTER_CATCH_EXCEPTIONS, Test);
1514
expect(metadata).to.be.eql(exceptions);
1615
});
17-
18-
describe('when one item is nil', () => {
19-
it('should throw an exception', () => {
20-
try {
21-
Catch(null)(Test);
22-
}
23-
catch (err) {
24-
expect(err).to.be.instanceof(InvalidDecoratorItemException);
25-
}
26-
});
27-
});
2816
});

packages/core/injector/injector.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ import { MiddlewareWrapper } from '../middleware/container';
1111
import { InstanceWrapper } from './container';
1212
import { Module } from './module';
1313

14+
/**
15+
* The type of an injectable dependency
16+
*/
17+
export type InjectorDependency = Type<any> | Function | string;
18+
19+
/**
20+
* Context of a dependency which gets injected by
21+
* the injector
22+
*/
23+
export interface InjectorDependencyContext {
24+
/**
25+
* The name of the function or injection token
26+
*/
27+
name?: string;
28+
/**
29+
* The index of the dependency which gets injected
30+
* from the dependencies array
31+
*/
32+
index: number;
33+
/**
34+
* The dependency array which gets injected
35+
*/
36+
dependencies: InjectorDependency[];
37+
}
38+
1439
export class Injector {
1540
public async loadInstanceOfMiddleware(
1641
wrapper: MiddlewareWrapper,
@@ -288,29 +313,4 @@ export class Injector {
288313
};
289314
return modules.concat.apply(modules, modules.map(flatten));
290315
}
291-
}
292-
293-
/**
294-
* The type of an injectable dependency
295-
*/
296-
export type InjectorDependency = Type<any> | Function | string;
297-
298-
/**
299-
* Context of a dependency which gets injected by
300-
* the injector
301-
*/
302-
export interface InjectorDependencyContext {
303-
/**
304-
* The name of the function or injection token
305-
*/
306-
name?: string;
307-
/**
308-
* The index of the dependency which gets injected
309-
* from the dependencies array
310-
*/
311-
index: number;
312-
/**
313-
* The dependency array which gets injected
314-
*/
315-
dependencies: InjectorDependency[];
316-
}
316+
}

sample/01-cats-app/src/common/filters/http-exception.filter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
2-
import { HttpException } from '@nestjs/common';
1+
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
32

4-
@Catch(HttpException)
3+
@Catch(3)
54
export class HttpExceptionFilter implements ExceptionFilter {
65
catch(exception: HttpException, host: ArgumentsHost) {
76
const ctx = host.switchToHttp();

0 commit comments

Comments
 (0)