Develop/[NestJs]
[NestJs] 예외 처리
CALLMESMITHMYNAME
2023. 5. 27. 17:56
반응형
그냥 뭐.. 정의 된 예외를 던져주면된다.
스프링이랑 이건 뭐 거의 동일하다.
getBoardById(id: string) : Board{
const board = this.boards.find((board) => board.id == id);
if(!board)
throw new NotFoundException();
return board
}

throw new NotFoundException("Not Found Exception");
이렇게 하면 Exception message까지 가능하다.
이렇게 확인까지 가능하다.
생각보다 간편하다.
ExceptionHandler 기능을 하는것도 있을것같은데...무튼 그렇다.
ExceptionHandler라기 보다는, 글로벌하기 파이프를 연결 하면.. 가능할 것같다
사실 스프링 aop,exceptionhandler 뭐 다 비슷비슷하니까
반응형