2015-04-15 16:04:42 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-04-15 16:04:42 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-04-15 16:04:42 +03:00
|
|
|
*
|
2018-05-11 05:06:46 +03:00
|
|
|
* @format
|
2016-03-02 15:27:13 +03:00
|
|
|
* @flow
|
2015-04-15 16:04:42 +03:00
|
|
|
*/
|
2018-05-11 05:06:46 +03:00
|
|
|
|
2016-02-11 13:44:24 +03:00
|
|
|
'use strict';
|
2016-02-11 13:20:59 +03:00
|
|
|
|
2018-11-26 17:24:05 +03:00
|
|
|
const Promise = require('promise/setimmediate/es6-extensions');
|
|
|
|
|
2019-03-28 06:45:03 +03:00
|
|
|
require('promise/setimmediate/done');
|
|
|
|
require('promise/setimmediate/finally');
|
2016-03-02 15:27:13 +03:00
|
|
|
|
2016-01-07 20:30:14 +03:00
|
|
|
if (__DEV__) {
|
|
|
|
require('promise/setimmediate/rejection-tracking').enable({
|
|
|
|
allRejections: true,
|
2016-08-02 17:48:29 +03:00
|
|
|
onUnhandled: (id, error = {}) => {
|
2017-03-10 01:22:17 +03:00
|
|
|
let message: string;
|
|
|
|
let stack: ?string;
|
|
|
|
|
|
|
|
const stringValue = Object.prototype.toString.call(error);
|
|
|
|
if (stringValue === '[object Error]') {
|
|
|
|
message = Error.prototype.toString.call(error);
|
|
|
|
stack = error.stack;
|
|
|
|
} else {
|
2019-11-20 03:20:37 +03:00
|
|
|
try {
|
|
|
|
message = require('pretty-format')(error);
|
|
|
|
} catch {
|
|
|
|
message = typeof error === 'string' ? error : JSON.stringify(error);
|
|
|
|
}
|
2017-03-10 01:22:17 +03:00
|
|
|
}
|
|
|
|
|
2016-01-07 20:30:14 +03:00
|
|
|
const warning =
|
|
|
|
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
|
2017-03-10 01:22:17 +03:00
|
|
|
`${message}\n` +
|
2016-01-07 20:30:14 +03:00
|
|
|
(stack == null ? '' : stack);
|
|
|
|
console.warn(warning);
|
|
|
|
},
|
2018-05-11 05:06:46 +03:00
|
|
|
onHandled: id => {
|
2016-01-07 20:30:14 +03:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2015-04-15 16:04:42 +03:00
|
|
|
|
|
|
|
module.exports = Promise;
|