Skip to content

Commit

Permalink
refactor: 에러 로깅 상수, 함수 분리 #93
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Nov 14, 2024
1 parent a6c5c62 commit 3547c19
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions backend/src/common/exception/filter/GlobalExceptionFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ export class BaseExceptionFilter implements ExceptionFilter {
const response = ctx.getResponse<Response>();

const status = exception.getStatus();
if (status >= 400 && status < 500) {
this.logger.warn(`${exception.getMessage()}`);
} else if (status >= 500) {
this.logger.error(`${exception.getMessage()}`);
}
logException(this.logger, exception.getMessage(), status);

return response.status(status).json({
code: exception.getCode(),
Expand All @@ -45,11 +41,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
: exception.message;

const status = exception.getStatus();
if (status >= 400 && status < 500) {
this.logger.warn(`${errorMessage}`);
} else if (status >= 500) {
this.logger.error(`${errorMessage}`);
}
logException(this.logger, errorMessage, status);

return response.status(status).json({
code: 9999,
Expand All @@ -67,6 +59,16 @@ export class HttpExceptionFilter implements ExceptionFilter {
}
}

function logException(logger: PinoLogger, message: string, status: number) {
const WARN = 400;
const ERROR = 500;

if (status < WARN) return;
void (status < ERROR
? logger.warn(`${message}`)
: logger.error(`${message}`));
}

@Catch()
export class UnknownExceptionFilter implements ExceptionFilter {
constructor(private readonly logger: PinoLogger) {}
Expand Down

0 comments on commit 3547c19

Please sign in to comment.