mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Add support for promise rejection tracking
Summary: Adds support for tracking unhandled rejections with `console.warn` (= yellow box). I will create a follow-up with proper error stack formatting. related: #4971 fixes: #4045, #4142 public {F59857438} {F59857439} Reviewed By: bestander Differential Revision: D2803126 fb-gh-sync-id: 376b33e42a967675a04338cbff3ec315a77d1037
This commit is contained in:
committed by
facebook-github-bot-3
parent
2b09614068
commit
b064094687
@@ -25,6 +25,26 @@
|
||||
global.setImmediate = require('setImmediate');
|
||||
var Promise = require('promise/setimmediate/es6-extensions');
|
||||
require('promise/setimmediate/done');
|
||||
if (__DEV__) {
|
||||
require('promise/setimmediate/rejection-tracking').enable({
|
||||
allRejections: true,
|
||||
onUnhandled: (id, error) => {
|
||||
const {message, stack} = error;
|
||||
const warning =
|
||||
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
|
||||
(message == null ? '' : `${message}\n`) +
|
||||
(stack == null ? '' : stack);
|
||||
console.warn(warning);
|
||||
},
|
||||
onHandled: (id) => {
|
||||
const warning =
|
||||
`Promise Rejection Handled (id: ${id})\n` +
|
||||
'This means you can ignore any previous messages of the form ' +
|
||||
`"Possible Unhandled Promise Rejection (id: ${id}):"`;
|
||||
console.warn(warning);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle either fulfillment or rejection with the same callback.
|
||||
|
||||
Reference in New Issue
Block a user