Skip to content
This repository was archived by the owner on Dec 6, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/common/errors/ApiError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,27 @@ export default class ApiError extends Error {
* @param isOperational 비즈니스 로직에서 발생한 정상 범위의 에러 여부
*/

constructor(
statusCode: number,
message: string,
code: ErrorCode = 'INTERNAL_ERROR',
details?: unknown,
isOperational = true
) {
constructor(statusCode: number, message: string, code?: ErrorCode, details?: unknown, isOperational = true) {
super(message);

// 상태 코드 자동 매핑
const fallbackCodeMap: Record<number, ErrorCode> = {
400: 'BAD_REQUEST',
401: 'UNAUTHORIZED',
403: 'FORBIDDEN',
404: 'NOT_FOUND',
409: 'CONFLICT',
422: 'UNPROCESSABLE',
429: 'TOO_MANY_REQUESTS',
500: 'INTERNAL_ERROR',
};

this.statusCode = statusCode;
this.code = code;
this.code = code ?? fallbackCodeMap[statusCode] ?? 'INTERNAL_ERROR';
this.details = details;
this.isOperational = isOperational;
this.name = 'ApiError';

Error.captureStackTrace?.(this, this.constructor);
}

Expand Down