mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
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:
parent
bb115dedb6
commit
396ad181d0
2 changed files with 5 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue