Skip to content

Commit

Permalink
fix(exceptionhandler): Better logging of unhandledPromiseRejections
Browse files Browse the repository at this point in the history
Summary:
There was cases were formatting the message for
unhandledPromiseRejection could attempt to add a property to a
string instead of an object cause more errors.

Semver: patch
  • Loading branch information
TerryMooreII committed Apr 6, 2022
1 parent 80320a3 commit 986b902
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/plugins/global-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ const addUnhandledrejection = () => {

/* istanbul ignore next */
const onUnhandledRejection = (e: any) => {
let error = {
message: '<unknown>',
};
let error = e;
let reason;

if ('reason' in e) {
error = e.reason;
reason = e.reason;
} else if (e && e.detail && e.detail.reason) {
error = e.detail.reason;
reason = e.detail.reason;
}

if (reason instanceof Error) {
error = reason;
} else if (typeof reason === 'string') {
error.message = reason;
} else {
error.message = '<unknown>';
}

error.message = `Uncaught (in promise) ${error.message}`;
Expand Down

0 comments on commit 986b902

Please sign in to comment.