-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: APIException DTO 추가 * style: HttpStatus ENUM 스타일 . 으로 변경, APIException.. Co-authored-by: lavi27 <[email protected]>
- Loading branch information
1 parent
f8b3559
commit 57d5ec0
Showing
16 changed files
with
133 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,37 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
|
||
export class APIError { | ||
/** | ||
* 에러 코드 (ENUM) | ||
* @example 'INTERNAL_SERVER_ERROR' | ||
*/ | ||
private code: string = APIErrorCodes['500']; | ||
constructor(status: HttpStatus, message: string, data?: any) { | ||
this._status = status; | ||
this._message = message; | ||
this._data = data; | ||
} | ||
|
||
/** | ||
* HTTP 상태 코드 | ||
* @example 500 | ||
* 에러 ENUM (ENUM Type) | ||
* @example HttpStatus.INTERNAL_SERVER_ERROR | ||
*/ | ||
private status: number = 500; | ||
private _status: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR; | ||
|
||
/** | ||
* 에러 메시지 | ||
* @example '내부 서버 오류가 발생했습니다.' | ||
*/ | ||
private message: string = '내부 서버 오류가 발생했습니다.'; | ||
private _message: string = '내부 서버 오류가 발생했습니다.'; | ||
|
||
private data?: any; | ||
private _data?: any; | ||
|
||
constructor(code, status, message, data?) { | ||
this.code = code; | ||
this.status = status; | ||
this.message = message; | ||
this.data = data; | ||
public get status() { | ||
return this._status; | ||
} | ||
} | ||
|
||
export const APIErrorCodes = { | ||
'400': 'BAD_REQUEST', | ||
'401': 'UNAUTHORIZED', | ||
'403': 'FORBIDDEN', | ||
'404': 'NOT_FOUND', | ||
'405': 'METHOD_NOT_ALLOWED', | ||
'409': 'CONFLICT', | ||
'410': 'GONE', | ||
'422': 'UNPROCESSABLE_CONTENT', | ||
'429': 'TOO_MANY_REQUESTS', | ||
'500': 'INTERNAL_SERVER_ERROR', | ||
'501': 'NOT_IMPLEMENTED', | ||
'503': 'SERVICE_UNAVAILABLE', | ||
}; | ||
public get message() { | ||
return this._message; | ||
} | ||
|
||
public get data() { | ||
return this._data; | ||
} | ||
} | ||
|
||
export default APIError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import APIError from './APIError.dto'; | ||
|
||
export default class APIException { | ||
constructor(status: HttpStatus, message: string, data?: any) { | ||
this._APIError = new APIError(status, message, data); | ||
this._status = status; | ||
} | ||
|
||
/** | ||
* 에러 ENUM (ENUM Type) | ||
* @example HttpStatus.INTERNAL_SERVER_ERROR | ||
*/ | ||
private _status: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR; | ||
|
||
private _APIError: APIError; | ||
|
||
public get status() { | ||
return this._status; | ||
} | ||
|
||
public get APIError() { | ||
return this._APIError; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.