Created
October 14, 2016 21:19
-
-
Save henkin/f5db722839fb61fe406763a0a558edc9 to your computer and use it in GitHub Desktop.
Handling errors in libraries
This file contains hidden or 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
function mainApp() { | |
libraryCode(input) | |
.then((data) => console.log("main output", formatForUserView(data))) | |
.catch((err) => { | |
console.error("error from library!", err); | |
display("user-friendly error message"); | |
}); | |
} | |
function libraryCode(input) { | |
let returnValue = {}; | |
return someLowLevelNodeOrNetworkFunction() | |
.then((result) => processLowLevelDataHere(result)) | |
.catch((err) => { | |
console.error("libraryCode had a problem calling someLowLevelNodeOrNetworkFunction with " + input, err); | |
cleanupResources(); | |
throw new Error("libraryCode puked", err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like it