Skip to content

Instantly share code, notes, and snippets.

@johnloy
Created January 23, 2020 13:55
Show Gist options
  • Save johnloy/33cadd0afb7983ce2de2bb69451a1cb2 to your computer and use it in GitHub Desktop.
Save johnloy/33cadd0afb7983ce2de2bb69451a1cb2 to your computer and use it in GitHub Desktop.
Determine if a value is an error, in a browser context
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