Skip to content

Commit

Permalink
fix: HttpToSocketExceptionFilter logger 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Jihoon Ko committed Sep 2, 2024
1 parent a10c63e commit e5c2ef4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/chat/application/http-to-socket-exception.filter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { ArgumentsHost, Catch, HttpException } from '@nestjs/common';
import { ArgumentsHost, Catch, HttpException, Logger } from '@nestjs/common';
import { BaseWsExceptionFilter } from '@nestjs/websockets';

@Catch(HttpException)
export class HttpToSocketExceptionFilter extends BaseWsExceptionFilter<HttpException> {
private readonly logger = new Logger(HttpToSocketExceptionFilter.name);

// BaseWsExceptionFilter를 상속하면 Ws관련 Exception을 만들 수 있다.

catch(exception: HttpException, host: ArgumentsHost): void {
const status = exception.getStatus();
if (500 <= status) {
this.logger.error('Server error', exception.message);
}

if (400 <= status && status < 500) {
this.logger.warn('BadRequest', exception.message);
}

const socket = host.switchToWs().getClient(); // 소켓 가져오기
socket.emit('exception', exception.getResponse());
}
Expand Down

0 comments on commit e5c2ef4

Please sign in to comment.