• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

리덕스 사가 회원가입 에러 관련 질문

19.09.24 21:46 작성 조회수 162

0

콘솔 창에서 "에러에러에러" 에러 메시지는 잘 확인 되는데, 정작 리덕스 state인 signUpErroReason에는 빈 객체만 들어갑니다. 어떻게 된 일인지 궁금합니다!

function* signUp() {
	try {
		// yield call(signUpAPI);
		yield delay(2000);
		throw new Error("에러에러에러");
		yield put({
			// put은 dispatch 동일
			type: SIGN_UP_SUCCESS
		});
	} catch (e) {
		// loginAPI 실패
		console.error(e);

		yield put({
			type: SIGN_UP_FAILURE,
			error: e
		});
	}
}

답변 5

·

답변을 작성해보세요.

1

네, state로 관리합니다. 객체일 필요는 없어서 message만 관리하기도 합니다.

0

Jiyeol Lee님의 프로필

Jiyeol Lee

질문자

2019.09.25

네 action.error.message로 하니까 "에러에러에러"가 들어가는게 리덕스 데브툴로 확인이 되네요 감사합니다. 그런데 실무에서는 그럼 에러 객체?(이 표현이 맞는지 모르겠지만) 자체를 리덕스 state로 관리를 보통 하는건가요?

0

근데 저기 데브툴에서 빈 객체로 나오는데 실제로도 빈 객체인가요? 아닐겁니다. action.error.message하면 에러 메시지가 나올거에요

0

Jiyeol Lee님의 프로필

Jiyeol Lee

질문자

2019.09.25

 case SIGN_UP_FAILURE: {
      return {
        ...state,
        isSigningUp: false,
        signUpErrorReason: action.error
      };
   }

제로초님이 짜신 코드와 동일하게 되어있습니다.

  1. Error: 에러에러에러 at signUp$ (http://localhost:3000/_next/static/development/pages/_app.js?ts=1569375119032:163006:17) at tryCatch (http://localhost:3000/_next/static/runtime/main.js?ts=1569375119032:11441:40) at Generator.invoke [as _invoke] (http://localhost:3000/_next/static/runtime/main.js?ts=1569375119032:11667:22) at Generator.prototype.<computed> [as next] (http://localhost:3000/_next/static/runtime/main.js?ts=1569375119032:11493:21) at next (http://localhost:3000/_next/static/development/pages/_app.js?ts=1569375119032:6367:29) at currCb (http://localhost:3000/_next/static/development/pages/_app.js?ts=1569375119032:6461:7)
    1. message"에러에러에러"
    2. stack"Error: 에러에러에러↵ at signUp$ (http://localhost:3000/_next/static/development/pages/_app.js?ts=1569375119032:163006:17)↵ at tryCatch (http://localhost:3000/_next/static/runtime/main.js?ts=1569375119032:11441:40)↵ at Generator.invoke [as _invoke] (http://localhost:3000/_next/static/runtime/main.js?ts=1569375119032:11667:22)↵ at Generator.prototype.<computed> [as next] (http://localhost:3000/_next/static/runtime/main.js?ts=1569375119032:11493:21)↵ at next (http://localhost:3000/_next/static/development/pages/_app.js?ts=1569375119032:6367:29)↵ at currCb (http://localhost:3000/_next/static/development/pages/_app.js?ts=1569375119032:6461:7)"

console.dir(e)는 위와 같이 출력되네요.

0

SIGN_UP_FAILURE 액션이 어떻게 되어있나요? 그리고 console.dir(e);도 한 번 해보세요.