Skip to content

Commit

Permalink
Add Service Unavailable logging
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Jan 13, 2025
1 parent 6b8d496 commit 55511c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/shared/error/global-exception.filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ describe('GlobalExceptionFilter', () => {
httpException.getResponse(),
httpException.getStatus(),
);
expect(loggerMock.crit).toHaveBeenCalledTimes(0);
});
});

describe('when filter catches HttpException Service Unavailable', () => {
it('should log request url with crit and pass it on to the http adapter', () => {
const httpException: HttpException = new HttpException('exception', 503);

sut.catch(httpException, argumentsHost);

expect(adapterImplMock.reply).toHaveBeenCalledTimes(1);
expect(adapterImplMock.reply).toHaveBeenCalledWith(
responseMock,
httpException.getResponse(),
httpException.getStatus(),
);
expect(loggerMock.crit).toHaveBeenCalledTimes(1);
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/shared/error/global-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class GlobalExceptionFilter implements ExceptionFilter {

if (exception instanceof Error) {
if (exception instanceof HttpException) {
if (exception.getStatus() === 503) {
const url: string = (ctx.getRequest() satisfies Request)?.url;
this.logger.crit(`503 Service Unavailable for URL: ${url}`);
}
httpAdapter.reply(ctx.getResponse(), exception.getResponse(), exception.getStatus());
} else if (exception instanceof DriverException) {
this.logger.crit(exception.message, exception.stack);
Expand Down

0 comments on commit 55511c9

Please sign in to comment.