mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
74d5d03dbd
Summary: This pre-suppresses the 153 error diff ahead of its release, since it is large. Changelog: [Internal] Reviewed By: mroch Differential Revision: D28754374 fbshipit-source-id: 1806f53bc7d804644d434583a2dcd6da63d00328
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict
|
|
*/
|
|
|
|
import typeof {enable} from 'promise/setimmediate/rejection-tracking';
|
|
|
|
type ExtractOptionsType = <P>((options?: ?P) => void) => P;
|
|
|
|
let rejectionTrackingOptions: $Call<ExtractOptionsType, enable> = {
|
|
allRejections: true,
|
|
onUnhandled: (id, rejection = {}) => {
|
|
let message: string;
|
|
let stack: ?string;
|
|
|
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
const stringValue = Object.prototype.toString.call(rejection);
|
|
if (stringValue === '[object Error]') {
|
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
message = Error.prototype.toString.call(rejection);
|
|
const error: Error = (rejection: $FlowFixMe);
|
|
stack = error.stack;
|
|
} else {
|
|
try {
|
|
message = require('pretty-format')(rejection);
|
|
} catch {
|
|
message =
|
|
typeof rejection === 'string'
|
|
? rejection
|
|
: JSON.stringify((rejection: $FlowFixMe));
|
|
}
|
|
}
|
|
|
|
const warning =
|
|
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
|
|
`${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);
|
|
},
|
|
};
|
|
|
|
export default rejectionTrackingOptions;
|