You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/components.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,7 +161,7 @@ export class HttpService<T> {
161
161
}
162
162
```
163
163
164
-
> warning **Warning** If your class doesn't extend another class, you should always prefer using **constructor-based** injection.
164
+
> warning **Warning** If your class doesn't extend another class, you should always prefer using **constructor-based** injection. The constructor explicitly outlines what dependencies are required and provides better visibility than class attributes annotated with `@Inject`.
Copy file name to clipboardExpand all lines: content/exception-filters.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ Here's an example overriding the entire response body and providing an error cau
70
70
asyncfindAll() {
71
71
try {
72
72
awaitthis.service.findAll()
73
-
} catch (error) {
73
+
} catch (error) {
74
74
thrownewHttpException({
75
75
status: HttpStatus.FORBIDDEN,
76
76
error: 'This is a custom message',
@@ -260,7 +260,7 @@ async create(createCatDto) {
260
260
261
261
> info **Hint** Prefer applying filters by using classes instead of instances when possible. It reduces **memory usage** since Nest can easily reuse instances of the same class across your entire module.
262
262
263
-
In the example above, the `HttpExceptionFilter` is applied only to the single `create()` route handler, making it method-scoped. Exception filters can be scoped at different levels: method-scoped of the controller/resolver/gateway, controller-scoped, or global-scoped.
263
+
In the example above, the `HttpExceptionFilter` is applied only to the single `create()` route handler, making it method-scoped. Exception filters can be scoped at different levels: method-scoped of the controller/resolver/gateway, controller-scoped, or global-scoped.
264
264
For example, to set up a filter as controller-scoped, you would do the following:
265
265
266
266
```typescript
@@ -383,8 +383,6 @@ export class AllExceptionsFilter extends BaseExceptionFilter {
383
383
384
384
> warning **Warning** Method-scoped and Controller-scoped filters that extend the `BaseExceptionFilter` should not be instantiated with `new`. Instead, let the framework instantiate them automatically.
385
385
386
-
The above implementation is just a shell demonstrating the approach. Your implementation of the extended exception filter would include your tailored **business** logic (e.g., handling various conditions).
387
-
388
386
Global filters **can** extend the base filter. This can be done in either of two ways.
389
387
390
388
The first method is to inject the `HttpAdapter` reference when instantiating the custom global filter:
0 commit comments