Skip to content

Commit 8562807

Browse files
committed
fix: 결제 에러 처리
1 parent 71c5744 commit 8562807

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

apps/ticket/src/app/(pages)/order/[orderId]/process/page.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useEffect, useState } from "react";
44
import { useRouter, useSearchParams } from "next/navigation";
5+
import { isAxiosError } from "axios";
56

67
import { usePaymentConfirmMutation } from "@/data/payments/postPaymentConfirm/mutation";
78
import { LoadingWithLayout } from "@/shared/components/LoadingWithLayout";
@@ -32,15 +33,21 @@ const PaymentProcessPage = () => {
3233
`${window.location.origin}/order/${searchParams.get("orderId")}/success?eventName=${encodeURIComponent(eventName)}&eventDate=${encodeURIComponent(eventDate)}`,
3334
);
3435
} catch (error) {
35-
// TODO: 에러 처리 로직 추가
3636
// 에러 메시지 세분화 요청
37-
// 결제 실패 페이지로 라우팅
38-
alert("결제 실패");
37+
if (isAxiosError(error)) {
38+
alert(error.message);
39+
}
3940

41+
// 결제 실패 페이지로 라우팅
4042
window.location.replace(
4143
`${window.location.origin}/order/${searchParams.get("orderId")}/fail`,
4244
);
45+
46+
return;
4347
}
48+
49+
alert("알 수 없는 이유로 결제에 실패했습니다. 다시 시도해주세요.");
50+
window.location.replace(`${window.location.origin}`);
4451
};
4552

4653
handlePaymentConfirm();

apps/ticket/src/lib/axios/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ instance.interceptors.response.use(
3939
return Promise.reject(error);
4040
}
4141

42-
if (error.response?.status === ERROR_CODE.SERVER_ERROR) {
42+
if (error.response?.status === 500) {
43+
// 결제 에러는 공통 alert 미노출
44+
if (error.response?.data.code === ERROR_CODE.PAYMENT) return;
45+
4346
alert("서버에러가 발생하였습니다. 관리자에게 문의해주세요.");
4447

4548
return;

apps/ticket/src/lib/axios/utils/errorCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export const ERROR_CODE = {
33
ACCESS_TOKEN_EXPIRED: 40103,
44
REFRESH_TOKEN_EXPIRED: 40104,
55
NO_ACCESS_TOKEN: 40403,
6-
SERVER_ERROR: 500,
6+
PAYMENT: 50004,
77
} as const;

0 commit comments

Comments
 (0)