v133 · javascript
Async Error Classifier
Promise chains catch many things: real Error objects, DOM exceptions, string rejections, plain objects, and values thrown by third-party code. Error.isError() is the only safe filter — it handles Proxy-wrapped errors, cross-realm throws, and future subclasses that instanceof misses.
Feature detection: checking…
With Error.isError()
async function fetchData(url) {
try {
return await fetch(url);
} catch (e) {
if (Error.isError(e)) {
// Real Error — log stack, retry
console.error(e.stack);
throw e;
}
// Unexpected throw shape
throw new Error(String(e));
}
}
// Rejection classifier
function classify(reason) {
if (!Error.isError(reason)) return 'non-error';
if (reason instanceof TypeError) return 'type-error';
if (reason instanceof DOMException) return 'dom';
return 'generic-error';
}
With instanceof only
async function fetchData(url) {
try {
return await fetch(url);
} catch (e) {
if (e instanceof Error) {
// Fails for cross-realm errors
// Fails for Proxy-wrapped errors
console.error(e.stack);
throw e;
}
throw new Error(String(e));
}
}
// Cross-realm iframe errors:
// iframeError instanceof Error → false
// Error.isError(iframeError) → true
// The native check just works.
Async pipeline — pick a scenario, run, watch the classifier
idle
Select a scenario above
Run a scenario to see the classifier in action.