개념

<aside> 🍎 어플리케이션에서 다루지 않은 예외를 잡아 처리하는 레이어

</aside>

Untitled

역할

<aside> 🍎 1. HttpException 타입 또는 그것을 상속한 클래스의 예외를 처리 2. 예외가 인식되지 않는(Unrecognized) 경우, 즉 HttpException 타입이 아닌 예외가 발생한 경우, 아래의 디폴트 JSON 응답을 생성

</aside>

{
  "statusCode": 500,
  "message": "Internal server error"
}

Standard Exceptions

<aside> 🍎 HttpException 클래스가 Nest 에 내장되어 있음

</aside>

HttpException 생성자

// nest/packages/common/exceptions/http.exception.ts

constructor(
    private readonly response: string | Record<string, any>,
    private readonly status: number,
    private readonly options?: HttpExceptionOptions,
  ) {
    super();
    this.initMessage();
    this.initName();
    this.initCause();
  }

JSON 응답 바디

{
  "statusCode": defaults to the HTTP status code provided in the status argument
  "message": a short description of the HTTP error based on the status
}