Skip to content

Commit abc3d7f

Browse files
author
maxbronnikov10
committed
fix(core): HTTP adapter error mapping
1 parent f2d8543 commit abc3d7f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/core/router/routes-resolver.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { BadRequestException, NotFoundException } from '@nestjs/common';
1+
import {
2+
BadRequestException,
3+
HttpException,
4+
NotFoundException,
5+
} from '@nestjs/common';
26
import {
37
HOST_METADATA,
48
MODULE_PATH,
@@ -185,11 +189,24 @@ export class RoutesResolver implements Resolver {
185189
// encoding, e.g. '%FF' (#8915)
186190
case err instanceof SyntaxError || err instanceof URIError:
187191
return new BadRequestException(err.message);
192+
case this.isHttpFastifyError(err):
193+
return new HttpException(err.message, err.statusCode);
188194
default:
189195
return err;
190196
}
191197
}
192198

199+
private isHttpFastifyError(
200+
error: any,
201+
): error is Error & { statusCode: number } {
202+
// condition based on this code - https://github.com/fastify/fastify-error/blob/d669b150a82968322f9f7be992b2f6b463272de3/index.js#L22
203+
return (
204+
error.statusCode !== undefined &&
205+
error instanceof Error &&
206+
error.name === 'FastifyError'
207+
);
208+
}
209+
193210
private getModulePathMetadata(metatype: Type<unknown>): string | undefined {
194211
const modulesContainer = this.container.getModules();
195212
const modulePath = Reflect.getMetadata(

0 commit comments

Comments
 (0)