Skip to content

Commit

Permalink
refactor: status code 관련 map(record) constants 디렉터리로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoung234 committed Aug 1, 2024
1 parent 1089a2e commit 025e152
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
18 changes: 6 additions & 12 deletions frontend/src/apis/ApiError.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from "axios";

const HTTP_STATUS = {
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
INTERNAL_SERVER_ERROR: 500,
} as const;
import { HTTP_STATUS_CODE_MAP } from "@constants/httpStatusCode";

class ApiError<T = unknown> extends Error implements AxiosError<T> {
config: InternalAxiosRequestConfig;
Expand All @@ -23,23 +17,23 @@ class ApiError<T = unknown> extends Error implements AxiosError<T> {
const errorStatus = error.response?.status || 0;
let name = "ApiError";

if (errorStatus === HTTP_STATUS.BAD_REQUEST) {
if (errorStatus === HTTP_STATUS_CODE_MAP.BAD_REQUEST) {
name = "ApiBadRequestError";
}

if (errorStatus === HTTP_STATUS.UNAUTHORIZED) {
if (errorStatus === HTTP_STATUS_CODE_MAP.UNAUTHORIZED) {
name = "ApiUnauthorizedError";
}

if (errorStatus === HTTP_STATUS.FORBIDDEN) {
if (errorStatus === HTTP_STATUS_CODE_MAP.FORBIDDEN) {
name = "ApiForbiddenError";
}

if (errorStatus === HTTP_STATUS.NOT_FOUND) {
if (errorStatus === HTTP_STATUS_CODE_MAP.NOT_FOUND) {
name = "ApiNotFoundError";
}

if (errorStatus === HTTP_STATUS.INTERNAL_SERVER_ERROR) {
if (errorStatus === HTTP_STATUS_CODE_MAP.INTERNAL_SERVER_ERROR) {
name = "ApiInternalServerError";
}

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/constants/httpStatusCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const HTTP_STATUS_CODE_MAP = {
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
INTERNAL_SERVER_ERROR: 500,
} as const;

0 comments on commit 025e152

Please sign in to comment.