Skip to content

Instantly share code, notes, and snippets.

@henkin
Created October 14, 2016 21:19
Show Gist options
  • Save henkin/f5db722839fb61fe406763a0a558edc9 to your computer and use it in GitHub Desktop.
Save henkin/f5db722839fb61fe406763a0a558edc9 to your computer and use it in GitHub Desktop.
Handling errors in libraries
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);
});
}
@cshipman
Copy link

I like it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment