Skip to content

Commit

Permalink
fix: check the logger level first
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehonal committed Sep 25, 2024
1 parent c650c22 commit d269dc8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions event-manager/src/__tests__/event.helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it, jest } from '@jest/globals';
import { getLogLevelByStatus, isErrorEvent } from '../event.helper.js';
import { HttpException, HttpStatus } from '@nestjs/common';
import { DefaultError } from '@nestjs-yalc/errors/default.error.js';
import { LogLevelEnum } from '@nestjs-yalc/logger/logger.enum.js';

describe('EventHelper', () => {
it('should return the correct log level', () => {
Expand All @@ -21,5 +22,11 @@ describe('EventHelper', () => {
errorClass: new HttpException('test', HttpStatus.BAD_REQUEST),
}),
).toBeFalsy();
expect(
isErrorEvent({
errorClass: HttpException,
logger: { level: LogLevelEnum.ERROR },
}),
).toBeTruthy();
});
});
7 changes: 7 additions & 0 deletions event-manager/src/event.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export function getLogLevelByStatus(statusCode: number) {
* Check if the event will trigger an error log
*/
export function isErrorEvent(options: IErrorEventOptions) {
if (
typeof options.logger === 'object' &&
options.logger.level === LogLevelEnum.ERROR
) {
return true;
}

if (!options.errorClass) {
return false;
}
Expand Down

0 comments on commit d269dc8

Please sign in to comment.