Skip to content

Instantly share code, notes, and snippets.

@pavermakov
Created April 15, 2020 10:27
Show Gist options
  • Save pavermakov/480aa09cd182908263bfcb8401195487 to your computer and use it in GitHub Desktop.
Save pavermakov/480aa09cd182908263bfcb8401195487 to your computer and use it in GitHub Desktop.
import { Alert } from "react-native";
export default function() {
require("promise/setimmediate/rejection-tracking").enable({
allRejections: true,
onUnhandled: (id, error = {}) => {
let message;
let stack;
const stringValue = Object.prototype.toString.call(error);
if (stringValue === "[object Error]") {
message = Error.prototype.toString.call(error);
stack = error.stack;
} else {
message = require("pretty-format")(error);
}
const warning =
`${`Possible Unhandled Promise Rejection (id: ${id}):\n` +
`${message}\n`}${
stack == null ? "" : stack}`;
Alert.alert(
"PROMISE ERROR",
warning,
[{ text: "Ok" }]
);
},
onHandled: () => {}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment