【发布时间】:2018-08-23 00:42:47
【问题描述】:
我不知道如何调用这个奇怪的异常,因为我的控制台上打印的异常消息没有给出任何提示和任何有意义的消息。因此,我无法为异常设置适当的标题。
该应用是使用 Expo 和 Redux 状态管理器开发的 调度状态后,我收到以下异常。
有趣的观察:
该操作是适当的,并且有效负载具有有效的 JSON 值。
当我在 reducer 中打印有效负载时,它正在打印正确的值
这里是代码
axios.post('API PATH', reqBody)
.then(response => {
dispatch({
type: CAMPAIGNS_FETCH_SUCCESS,
payload: response.data.campaigns
});
})
.catch(error => {
console.error('error occured while fetching campaigns: ', JSON.stringify(error));
});
对于上面的代码,一旦我将控件发送到reducer 并且reducer 正在打印正确的值,但之后我得到以下异常
error occured while fetching campaigns: , {"line":163362,"column":43,"sourceURL":"http://packager.kk.camp.exp.direct:80/./node_modules/react-native-scripts/build/bin/crna-entry.bundle?platform=android&dev=true&hot=false&minify=false"}
- node_modules/react-native/Libraries/ReactNative/YellowBox.js:67:16 in error
* src/screens/CampaignActions/
CampaignActions.js:125:22 in <unknown>
- node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
- node_modules/promise/setimmediate/core.js:123:25 in <unknown>
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:295:23 in <unknown>
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:148:6 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:196:17 in _callImmediatesPass
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:464:11 in callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:282:4 in __callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:137:6 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:269:6 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:136:17 in flushedQueue
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:11 in callFunctionReturnFlushedQueue
有什么帮助吗?这对我来说需要很多时间。
【问题讨论】:
-
在你做的时候分派payload是很危险的。 response.data 可以是未定义的,所以会抛出错误。您应该在调度此操作之前检查您是否真的有 response.data
标签: react-native redux react-redux react-native-android