Created
January 23, 2020 13:55
-
-
Save johnloy/33cadd0afb7983ce2de2bb69451a1cb2 to your computer and use it in GitHub Desktop.
Determine if a value is an error, in a browser context
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
function isError(value) { | |
switch (Object.prototype.toString.call(value)) { | |
case '[object Error]': | |
return true; | |
case '[object Exception]': | |
return true; | |
case '[object DOMException]': | |
return true; | |
default: | |
return value instanceof Error; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment