Skip to content

Instantly share code, notes, and snippets.

@earnubs
Created May 20, 2019 11:31
Show Gist options
  • Save earnubs/5f47a6d75ae761ce7e2b9436bfd900aa to your computer and use it in GitHub Desktop.
Save earnubs/5f47a6d75ae761ce7e2b9436bfd900aa to your computer and use it in GitHub Desktop.
const callApi = () => {
const response = fetch(...);
// do stuff with response
return response;
}
try {
const response = callApi();
next(completeAction(response));
}
catch (e) {
captureException(error);
next(completeAction(error));
}
//
// Versus
//
const callApi = () => {
// a specfic try/catch for the fetch
try {
return fetch(...);
}
// do stuff with response
catch (error) {
captureException(error); // get a precise stacktrace
throw error;
}
}
try {
const response = callApi();
next(completeAction(response));
}
catch (error) {
captureException(error);
next(completeAction(new Error('CALL_API Error')));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment