Skip to content

Commit

Permalink
Merge pull request #100 from skevy/native-promise-rejection-tracking
Browse files Browse the repository at this point in the history
Add support for promise rejection tracking in native Promise polyfill
  • Loading branch information
zpao committed Jan 27, 2016
2 parents b9dba88 + 09f5922 commit a2e5278
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"core-js": "^1.0.0",
"loose-envify": "^1.0.0",
"isomorphic-fetch": "^2.1.1",
"promise": "^7.0.3",
"promise": "^7.1.1",
"ua-parser-js": "^0.7.9"
},
"devEngines": {
Expand Down
21 changes: 21 additions & 0 deletions src/__forks__/Promise.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@
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.
*/
Expand Down

0 comments on commit a2e5278

Please sign in to comment.