Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce non error objects into errors before sending to sentry #1874

Merged
merged 3 commits into from
Oct 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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