<aside> 🍎 어플리케이션에서 다루지 않은 예외를 잡아 처리하는 레이어
</aside>
<aside> 🍎 1. HttpException 타입 또는 그것을 상속한 클래스의 예외를 처리 2. 예외가 인식되지 않는(Unrecognized) 경우, 즉 HttpException 타입이 아닌 예외가 발생한 경우, 아래의 디폴트 JSON 응답을 생성
</aside>
{
"statusCode": 500,
"message": "Internal server error"
}
<aside> 🍎 HttpException 클래스가 Nest 에 내장되어 있음
</aside>
// 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();
}
response
: Defines the JSON response body. It can be a string
or an object
as described below.status
: Defines the HTTP status codeoptions
: Provides an error **cause.** This cause
object is not serialized into the response object, but it can be useful for logging purposes, providing valuable information about the inner error that caused the HttpException
to be thrown.{
"statusCode": defaults to the HTTP status code provided in the status argument
"message": a short description of the HTTP error based on the status
}