Skip to content

Commit

Permalink
Merge pull request #6 from gsainfoteam/5-handle-409-error
Browse files Browse the repository at this point in the history
🚸 Add 'already registered' error handling
  • Loading branch information
dohyun-ko authored Mar 7, 2024
2 parents dc5fbae + 6613ba4 commit 46fe7ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/locales/ko-KR/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const main = {
action: "회원가입",
back: "로그인 페이지로 돌아가기",
error: "회원가입에 실패하였습니다.",
duplicate: "이미 가입된 이메일입니다.",
success: "회원가입이 완료되었습니다.",
},
profile: {
Expand Down
14 changes: 13 additions & 1 deletion src/pages/Register/useRegister.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from "axios";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate, useSearchParams } from "react-router-dom";
Expand Down Expand Up @@ -187,7 +188,18 @@ const useRegister = () => {
confirmButtonText: t("register.back"),
});
navigate(loginPageUri || "/");
} catch {
} catch (e) {
if (e instanceof AxiosError) {
if (e.response?.status === 409) {
Swal.fire({
icon: "error",
title: "Oops...",
text: t("register.duplicate"),
});
return;
}
}

Swal.fire({
icon: "error",
title: "Oops...",
Expand Down

0 comments on commit 46fe7ad

Please sign in to comment.