https://github.com/wayou/nest-global-filter-injection-issue
https://github.com/wayou/nest-global-filter-injection-issue
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/wayou/nest-global-filter-injection-issue
- Owner: wayou
- Created: 2020-06-19T13:43:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T02:59:53.000Z (over 2 years ago)
- Last Synced: 2025-02-10T15:50:36.222Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.5 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
According to [the doc](https://docs.nestjs.com/exception-filters#exception-filters-1),
if using `app.useGlobalFilters(new HttpExceptionFilter());` to register the filter, the filter cannot be injected directly, but:
```ts
import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';@Module({
providers: [
{
provide: APP_FILTER,
useClass: HttpExceptionFilter,
},
],
})
export class AppModule {}
```however, in this repo I still can inject the filter normally:
[src/cats/cats.controller.ts](./src/cats/cats.controller.ts)
```diff
import { Controller, ForbiddenException, Get } from '@nestjs/common';
import { HttpExceptionFilter } from '../exception/http-excption.filter';@Controller('cats')
export class CatsController {
+ constructor(private readonly filter: HttpExceptionFilter) {
+ console.log('look, the filter been injected', this.filter);
+ }
@Get()
async create() {
throw new ForbiddenException();
}
}```