Javascript 如何将错误从承诺返回到redux saga catch块?现在获取未定义的错误
在我的传奇故事中,我正在调用一个firebase函数。该函数工作正常,如果返回错误,则返回到saga的catch块。但是没有传递错误变量。代码如下:Javascript 如何将错误从承诺返回到redux saga catch块?现在获取未定义的错误,javascript,redux,redux-saga,Javascript,Redux,Redux Saga,在我的传奇故事中,我正在调用一个firebase函数。该函数工作正常,如果返回错误,则返回到saga的catch块。但是没有传递错误变量。代码如下: const firebaseAuth = ({ email, password }) => firebase.auth().signInWithEmailAndPassword(email, password) .catch((error) => { throw error; }); function* loginUse
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;
当前,当程序在
调试器
语句处中断时,错误未定义。知道如何解决这个问题吗?我认为应该在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 });
}
}
我认为应该在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 });
}
}
您是否尝试过将调试器放入promise catch函数中
.catch((error)=>{debugger;throw error;})代码>。。。错误变量是否也未定义?是否尝试将调试器放入promise catch函数中.catch((error)=>{debugger;throw error;})代码>。。。错误变量也没有定义吗?我认为这不会有帮助。catch
方法是异步的,因此在try/catch
中定义回调将无效。我认为这不会有什么帮助。catch
方法是异步的,因此在try/catch
中定义回调将无效。