Created
May 20, 2019 11:31
-
-
Save earnubs/5f47a6d75ae761ce7e2b9436bfd900aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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