Skip to content

Commit

Permalink
create specific errors for string and object types
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Oct 13, 2020
1 parent 445213a commit 3ef6780
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/util/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ export default class Logger {
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');
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 (__DEV__) {
Expand Down

0 comments on commit 3ef6780

Please sign in to comment.