Created
August 25, 2020 08:18
-
-
Save rgabaydullov/1799790b3ba4c18eec75afe608aff993 to your computer and use it in GitHub Desktop.
VanillaJS error handling example
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
/* middleware может принимать любое количество аргументов любых типов */ | |
const middleware = (...args) => { | |
const [event, ...data] = args; | |
if (event.error) { | |
/* поймали объект экземпляр Error */ | |
return event.error; | |
} | |
/* поймали непростое исключение, передаем дальше... */ | |
return data; | |
} | |
window.addEventListener('error', middleware); | |
window.onerror = middleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment