Skip to content

Instantly share code, notes, and snippets.

@rgabaydullov
Created August 26, 2020 10:30
Show Gist options
  • Select an option

  • Save rgabaydullov/e0d757fcdb6c498aaa523c14e87e2ec2 to your computer and use it in GitHub Desktop.

Select an option

Save rgabaydullov/e0d757fcdb6c498aaa523c14e87e2ec2 to your computer and use it in GitHub Desktop.
Event-based error handling example
// ...
const wrapEventWithExcpetionHandler = (middleware) => (e) => {
const { error } = e; // предположим, что ошибка в этом поле
if (error) {
throw new Error(error);
}
try {
return middleware(e);
} catch (err) {
throw new Error(err);
}
}
window.addEventListener('mousemove', wrapEventWithExceptionHandler(middlewareGlobalMouseMove));
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment