2017-08-14 54 views
0

我在我的傳奇中調用了firebase函數。該功能正常工作,如果錯誤返回,它來到傳奇的catch塊。但是錯誤變量沒有通過。下面的代碼:如何將承諾中的錯誤返回到REDX傳奇catch塊?現在得到錯誤undefined

const firebaseAuth = ({ email, password }) => 
    firebase.auth().signInWithEmailAndPassword(email, password) 
    .catch((error) => { throw error; }); 


function* loginUser(action) { 
    try { 
    const user = yield call(firebaseAuth, action.payload); 

    yield put({ type: USER_LOGIN_SUCCESS, payload: { user } }); 
    } catch (error) { 
    /* eslint-disable no-debugger */ 
    debugger; 

    // I need to see the error here. 

    yield put({ type: USER_LOGIN_FAIL }); 
    } 
} 

function* sessionSaga() { 
    yield takeEvery(USER_LOGGING_IN, loginUser); 
} 

export default sessionSaga; 

目前,當在debugger聲明的程序中斷,錯誤是不確定的。任何想法如何解決這個問題?

+0

你試圖把調試到承諾捕捉功能? '.catch((error)=> {debugger; throw error;});'...那裏的錯誤變量是不確定的嗎? –

回答

0

Ι想你應該添加您的函數調用無極您try-catch塊內:

function* loginUser(action) { 
    try { 
     const firebaseAuth = ({ email, password }) => 
     firebase.auth().signInWithEmailAndPassword(email, password) 
     .catch((error) => { throw error; }); 

    const user = yield call(firebaseAuth, action.payload); 

    yield put({ type: USER_LOGIN_SUCCESS, payload: { user } }); 
    } catch (error) { 
    /* eslint-disable no-debugger */ 
    debugger; 

    // I need to see the error here. 

    yield put({ type: USER_LOGIN_FAIL }); 
    } 
} 
+0

我不認爲這會有所幫助。 catch方法是異步的,因此在try/catch中定義回調將不起作用。 –