Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed May 2, 2024
2 parents f388573 + 13a26ae commit a2731f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion content/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class HttpService<T> {
}
```

> warning **Warning** If your class doesn't extend another class, you should always prefer using **constructor-based** injection.
> 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`.
#### Provider registration

Expand Down
6 changes: 2 additions & 4 deletions content/exception-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Here's an example overriding the entire response body and providing an error cau
async findAll() {
try {
await this.service.findAll()
} catch (error) {
} catch (error) {
throw new HttpException({
status: HttpStatus.FORBIDDEN,
error: 'This is a custom message',
Expand Down Expand Up @@ -260,7 +260,7 @@ async create(createCatDto) {

> 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.
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.
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.
For example, to set up a filter as controller-scoped, you would do the following:

```typescript
Expand Down Expand Up @@ -383,8 +383,6 @@ export class AllExceptionsFilter extends BaseExceptionFilter {

> 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.
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).

Global filters **can** extend the base filter. This can be done in either of two ways.

The first method is to inject the `HttpAdapter` reference when instantiating the custom global filter:
Expand Down

0 comments on commit a2731f8

Please sign in to comment.