所以,我有一个传奇:
export function * initSignUp (action) {
try {
yield call(signUp, action.signUpDetails)
} catch (err) {
console.log('caught in initSignUp', err)
yield put({ type: 'SIGN_UP_FAIL', err, action })
}
}
哪个正在调用(调用?正在排队?)另一个:
export function * signUp (action) {
try {
let response = yield Auth.signUp({...})
yield put(addData({...}))
} catch (err) {
console.log('caught in signUp', err)
throw new Error(err)
}
}
如果此处的内部传奇在yield Auth.signUp()
上失败,那么将命中第一个catch块,但是抛出错误将导致未捕获的异常。
我同时尝试了throw new Error(err)
和return Promise.reject(err)
,尽管后者更正常地失败了,但我仍然从不碰到“陷入initSignUp”行。
为什么我不能在catch
中initSignUp()
出现此错误?
编辑:
initSignUp的调用方式如下:
function * onboardingSaga () {
yield all([
takeEvery(INIT_SIGN_UP, initSignUp),
...
并注册:
function * authSaga () {
yield all([
takeEvery(SIGN_UP, signUp),
...
rootSaga:
export default function * rootSaga () {
yield all([
OnboardingSaga(),
AuthSaga()
])
}
Stacktrace:
[14:04:16] uncaught at rootSaga, at rootSaga
at rootSaga
at takeEvery
at signUp
TypeError: Cannot read property 'username' of undefined
at signUp$ (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:224959:89)
at tryCatch (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:20888:19)
at Generator.invoke [as _invoke] (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:21063:24)
at Generator.prototype.(anonymous function) [as next] (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:20931:23)
at next (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:149528:29)
at proc (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:149503:5)
at runForkEffect (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:149744:21)
at runEffect (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:149629:770)
at next (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:149532:11)
at currCb (blob:http://192.168.178.27:19001/d74267c7-c785-4744-a144-ed0c708da730:149606:9)
- node_modules\expo\build\logs\LogSerialization.js:145:14 in _captureConsoleStackTrace
- node_modules\expo\build\logs\LogSerialization.js:40:24 in Object.serializeLogDataAsync$
- ... 9 more stack frames from framework internals