Skip to content

Instantly share code, notes, and snippets.

@Olegas
Created June 14, 2019 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Olegas/1a43c99481095f3f95593275aa985e75 to your computer and use it in GitHub Desktop.
Save Olegas/1a43c99481095f3f95593275aa985e75 to your computer and use it in GitHub Desktop.
function apiWrapper(args) {
const method = getMethodSomehow(args); // Тут мы как-то получили someAppliedAPI
return method(args).catch((e) => {
// это общий обработчик
})
}
function someAppliedAPI(args) {
return doSomeAsync(args).catch((e) => {
if (e instanceof MyAppliedError) {
// deal with it
} else {
throw e; // Делегируем дефолтному обработчику если не можем сами справиться
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment