Skip to content

Commit

Permalink
fix: type orm not found exceptions return 404
Browse files Browse the repository at this point in the history
  • Loading branch information
microwavekonijn committed Oct 11, 2022
1 parent 9b674ea commit 365cf4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/filters/type-orm.filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {BaseExceptionFilter} from '@nestjs/core';
import {Catch, NotFoundException} from '@nestjs/common';
import {EntityNotFoundError} from 'typeorm';

@Catch(EntityNotFoundError)
export class TypeOrmFilter extends BaseExceptionFilter {
catch(): void {
throw new NotFoundException();
}
}
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {AppModule} from './app.module';
import {DocumentBuilder, SwaggerModule} from '@nestjs/swagger';
import compression from 'fastify-compress';
import {ValidationPipe} from '@nestjs/common';
import {TypeOrmFilter} from './filters/type-orm.filter';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestFastifyApplication>(
Expand All @@ -21,6 +22,8 @@ async function bootstrap(): Promise<void> {

const config = app.get(ConfigService);

app.useGlobalFilters(new TypeOrmFilter());

app.enableCors(config.get('config'));
void app.register(fastifyHelmet, {
contentSecurityPolicy: {
Expand Down

0 comments on commit 365cf4f

Please sign in to comment.