【发布时间】:2019-04-22 20:57:22
【问题描述】:
在处理大型继承代码库时,我偶然发现了这个不太有用的警告:
Possible Unhandled Promise Rejection (id: 0):
true
console.warn @ YellowBox.js:67
onUnhandled @ Promise.js:43
onUnhandled @ rejection-tracking.js:71
(anonymous) @ JSTimers.js:256
_callTimer @ JSTimers.js:152
callTimers @ JSTimers.js:405
__callFunction @ MessageQueue.js:349
(anonymous) @ MessageQueue.js:106
__guard @ MessageQueue.js:297
callFunctionReturnFlushedQueue @ MessageQueue.js:105
(anonymous) @ debuggerWorker.js:72
是否有可能获得导致此拒绝的承诺的文件和行号,而无需遍历整个代码并在任何地方添加 catch()?
【问题讨论】:
-
这个生命周期方法应该可以帮到你
componentDidCatch -
您是使用 fetch 还是 axis 来获取数据?使用 axios,您可以使用拦截器功能并在那里添加更多日志记录。我认为您也可以使用 fetch 来做到这一点。
-
@needsleep 应用程序使用 fetch,但问题适用于所有未处理的承诺
标签: react-native