Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ResponseError class #89

Merged
merged 5 commits into from
Dec 9, 2023
Merged

feat: add ResponseError class #89

merged 5 commits into from
Dec 9, 2023

Conversation

Jinho1011
Copy link
Member

closes #88

    const data = await response.json();

    if (!response.ok) {
      throw new ResponseError(data);
    }

    return data as TData;

이제 fetch.post를 사용할 때 에러가 response가 ok가 아니라면(=200~299) ResponseError를 throw합니다.

이 에러를 던지는 fetch를 사용하는 쪽에서는 이렇게 에러 핸들링을 하면 됩니다.

      try {
        const response = await kakaoLogin(kakaoCode);
        if (response && response.accessToken) {
          response.newMember ? navigate('/onboard') : navigate('/');
        }
      } catch (err) {
        if (err instanceof ResponseError) {
          if (err.errorData.abCode === 'ILLEGAL_JOIN_STATUS') {
            navigate(`/signup`, { state: { memberId: err.errorData.errorContent.payload } });
          }
        }
      }

저 에러 코드 ILLEGAL_JOIN_STATUS는 enum이나 상수로 관리해야할 필요가 보이네요

다음 PR 때 반영하겠습니다.

@Jinho1011
Copy link
Member Author

좋습니다, 에이전트 Jeon.

병합하도록 하겠습니다.

@Jinho1011 Jinho1011 merged commit ead4928 into dev Dec 9, 2023
1 check passed
@Jinho1011 Jinho1011 deleted the fix/kakao-login-flow branch December 9, 2023 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AUTH_REGISTERED인 유저를 개인정보 입력 화면으로 이동
1 participant