Created
August 26, 2020 10:30
-
-
Save rgabaydullov/e0d757fcdb6c498aaa523c14e87e2ec2 to your computer and use it in GitHub Desktop.
Event-based error handling example
This file contains hidden or 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
| // ... | |
| 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