Answer the question
In order to leave comments, you need to log in
Why inject httpServer into Nest's global filter?
I understood this: in order for our filter to extend the behavior of the base filter, it is enough to inherit the functionality from BaseExceptionFilter
, and then bind the filter like this:
class FilterThatExtendsBaseExceptionFilter extends BaseExceptionFilter {...}
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new FilterThatExtendsBaseExceptionFilter()); // здесь httpAdapter'a нет
await app.listen(3000);
}
httpAdapter
if we have already inherited functionality from BaseExceptionFilter
?const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); // зачем здесь httpAdapter?
Global filters can extend the base filter. This can be done in either of two ways.
The first method is to inject the HttpServer reference when instantiating the custom global filter:
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question