Created
June 14, 2019 10:00
-
-
Save Olegas/1a43c99481095f3f95593275aa985e75 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
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