Allow Promise to display error strings and not just error objects.

Summary: Closes https://github.com/facebook/react-native/pull/9989

Reviewed By: bestander

Differential Revision: D4147256

Pulled By: hramos

fbshipit-source-id: 62d49b592391bad434062e3c0d9c8287842664a8
This commit is contained in:
Mike Lambert 2017-03-09 14:22:17 -08:00 committed by Facebook Github Bot
parent d2796ea4ed
commit bfb2766c63
2 changed files with 15 additions and 2 deletions

View File

@ -13,14 +13,26 @@
const Promise = require('fbjs/lib/Promise.native'); const Promise = require('fbjs/lib/Promise.native');
const prettyFormat = require('pretty-format');
if (__DEV__) { if (__DEV__) {
require('promise/setimmediate/rejection-tracking').enable({ require('promise/setimmediate/rejection-tracking').enable({
allRejections: true, allRejections: true,
onUnhandled: (id, error = {}) => { onUnhandled: (id, error = {}) => {
const {message = null, stack = null} = error; 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 {
message = prettyFormat(error);
}
const warning = const warning =
`Possible Unhandled Promise Rejection (id: ${id}):\n` + `Possible Unhandled Promise Rejection (id: ${id}):\n` +
(message == null ? '' : `${message}\n`) + `${message}\n` +
(stack == null ? '' : stack); (stack == null ? '' : stack);
console.warn(warning); console.warn(warning);
}, },

View File

@ -184,6 +184,7 @@
"opn": "^3.0.2", "opn": "^3.0.2",
"optimist": "^0.6.1", "optimist": "^0.6.1",
"plist": "^1.2.0", "plist": "^1.2.0",
"pretty-format": "^4.2.1",
"promise": "^7.1.1", "promise": "^7.1.1",
"react-clone-referenced-element": "^1.0.1", "react-clone-referenced-element": "^1.0.1",
"react-devtools-core": "^2.0.8", "react-devtools-core": "^2.0.8",