fix: correctly initialize exception mapping

The constructor of an exception filter must be given
an instance of HttpAdapterHost, otherwise it will crash at runtime.

This can be reproduced by GETing /.

Reference: https://docs.nestjs.com/exception-filters#inheritance
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-02-11 19:20:54 +01:00
parent bb115dedb6
commit 396ad181d0
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 5 additions and 2 deletions

View file

@ -6,6 +6,7 @@
import {
ArgumentsHost,
BadRequestException,
Catch,
ConflictException,
InternalServerErrorException,
NotFoundException,
@ -67,6 +68,7 @@ const mapOfHedgeDocErrorsToHttpErrors: Map<string, HttpExceptionConstructor> =
],
]);
@Catch()
export class ErrorExceptionMapping extends BaseExceptionFilter<Error> {
catch(error: Error, host: ArgumentsHost): void {
super.catch(ErrorExceptionMapping.transformError(error), host);

View file

@ -5,7 +5,7 @@
*/
import { LogLevel } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
@ -79,7 +79,8 @@ async function bootstrap(): Promise<void> {
app.useStaticAssets('public', {
prefix: '/public/',
});
app.useGlobalFilters(new ErrorExceptionMapping());
const { httpAdapter } = app.get(HttpAdapterHost);
app.useGlobalFilters(new ErrorExceptionMapping(httpAdapter));
await app.listen(appConfig.port);
logger.log(`Listening on port ${appConfig.port}`, 'AppBootstrap');
}