Nest.js Error 처리

김세겸·2023년 1월 3일
0

code-camp

목록 보기
8/10

1. try, catch, finally

try, catch => 쓰는 경우 service와 같이 데이터 로직
finally => 성공 실패 상관없이 무조건 실행

2. exception-filter

commons - filter - http-exception.filter.ts

@Catch(HttpExcption)
class HttpExceptionFilter impletments ExceptionFilter {
	catch(exception: HttpException) {
    	const status = exception.getStatus();
        const message = exception.message;
        
        // 로직...
    }
}

main.ts에 등록

app.useGlobalFilters(new HttpExceptionFilter());
``

0개의 댓글