Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
VanillaJS error handling example
/* 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