Last active
April 11, 2024 19:24
-
-
Save JamesTheAwesomeDude/2149956256a4c33e9163c8278c289ed2 to your computer and use it in GitHub Desktop.
JavaScript convert error event to error object
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
export function error_fromEvent(event) { | |
const error = new Error(event.message, {cause: event}); | |
if (event.type === 'error') | |
error.name = `${event.target.__proto__.constructor.name}Error`; | |
else | |
error.name = `${event.__proto__.constructor.name}`; | |
return error; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment