Skip to content

Commit

Permalink
Merge pull request #1572 from luddwichr/add-missing-error-handler-next
Browse files Browse the repository at this point in the history
fix: pass unhandled error on to next express error handler
  • Loading branch information
kamilmysliwiec authored Feb 6, 2025
2 parents 678d76c + 1aa5d8d commit 6a67390
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/loaders/express.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export class ExpressLoader extends AbstractLoader {
throw new NotFoundException(err.message);
} else if (err?.code === 'ENOENT') {
throw new NotFoundException(`ENOENT: ${err.message}`);
} else {
next(err);
}
});
});
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/express-adapter.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ describe('Express adapter', () => {
let server: Server;
let app: INestApplication;

describe('when middleware throws generic error', () => {
beforeAll(async () => {
app = await NestFactory.create(AppModule.withDefaults(), {
logger: new NoopLogger()
});
app.use((_req, _res, next) => next(new Error('Something went wrong')));

server = app.getHttpServer();
await app.init();
});

describe('GET /index.html', () => {
it('should return Iternal Server Error', async () => {
return request(server).get('/index.html').expect(500);
});
});
});

describe('when "fallthrough" option is set to "true"', () => {
beforeAll(async () => {
app = await NestFactory.create(AppModule.withFallthrough(), {
Expand Down

0 comments on commit 6a67390

Please sign in to comment.