Skip to content

Commit

Permalink
Coerce non error objects into errors before sending to sentry (#1874)
Browse files Browse the repository at this point in the history
* Coerce non error objects into errors

It seems like we're passing non errors to sentry

re: https://sentry.io/organizations/metamask/issues/1641747298/?project=2299799&query=is%3Aunresolved&statsPeriod=14d

I realise we should fix this underlying issue, but adding this will allow us to make mistakes without upsetting the Sentry gods
At least, that's my hope 🙏
  • Loading branch information
rickycodes authored Oct 13, 2020
1 parent 8599838 commit d3f0aed
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/util/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,31 @@ export default class Logger {
if (__DEV__) {
console.warn(DEBUG, error); // eslint-disable-line no-console
} else if (metricsOptIn === AGREED) {
let exception = error.error || error.message || error.originalError || error;
if (!(error instanceof Error)) {
const type = typeof error;
switch (type) {
case 'string':
exception = new Error(error);
break;
case 'object':
exception = new Error(JSON.stringify(error));
break;
default:
exception = new Error('error to capture is not an error instance');
}
exception.originalError = error;
}
if (extra) {
if (typeof extra === 'string') {
extra = { message: extra };
}
withScope(scope => {
scope.setExtras(extra);
captureException(error);
captureException(exception);
});
} else {
captureException(error);
captureException(exception);
}
}
}
Expand Down

0 comments on commit d3f0aed

Please sign in to comment.