Skip to content

Commit

Permalink
Coerce non error objects into errors
Browse files Browse the repository at this point in the history
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 committed Oct 3, 2020
1 parent 85d3365 commit 7e49ded
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/util/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default class Logger {
static async error(error, extra) {
// Check if user passed accepted opt-in to metrics
const metricsOptIn = await AsyncStorage.getItem(METRICS_OPT_IN);
let exception = error.error || error.message || error.originalError || error;
if (!(error instanceof Error)) {
exception = new Error('error to capture is not an error instance');
exception.originalError = error;
}
if (__DEV__) {
console.warn(DEBUG, error); // eslint-disable-line no-console
} else if (metricsOptIn === AGREED) {
Expand All @@ -49,10 +54,10 @@ export default class Logger {
}
withScope(scope => {
scope.setExtras(extra);
captureException(error);
captureException(exception);
});
} else {
captureException(error);
captureException(exception);
}
}
}
Expand Down

0 comments on commit 7e49ded

Please sign in to comment.