You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've defined a custom error type in a React application, which I'm throwing. I have an error boundary defined at the top of my application's component tree whose purpose is to catch uncaught errors and display an error page. The error boundary is catching the custom error, but isn't able to distinguish it from an error of type Error. Put simply, custom error types, created with the following syntax:
class CustomError extends Error {}
... are, from the error boundary's perspective, simply errors of type Error, not CustomError. Further illustration – even though I'm explicitly throwing a CustomError, the error boundary's componentDidCatch method thinks its error argument is of type Error.
This issue is reproduced here: https://codepen.io/heywilly/pen/wyrKjz – the code is all documented, butin a nutshell, I've implemented an Application component that wraps its contents in an error boundary. A custom error is thrown from a subcomponent, and the custom typing gets lost somewhere along the way. That is, from the error boundary's perspective, the error that's thrown is of type Error, not the custom type defined in the application.
I think I may have found a bug in React.
I've defined a custom error type in a React application, which I'm throwing. I have an error boundary defined at the top of my application's component tree whose purpose is to catch uncaught errors and display an error page. The error boundary is catching the custom error, but isn't able to distinguish it from an error of type
Error
. Put simply, custom error types, created with the following syntax:... are, from the error boundary's perspective, simply errors of type
Error
, notCustomError
. Further illustration – even though I'm explicitly throwing aCustomError
, the error boundary'scomponentDidCatch
method thinks its error argument is of typeError
.Am I crazy or is this a bug in React?
This issue is reproduced here: https://codepen.io/heywilly/pen/wyrKjz – the code is all documented, butin a nutshell, I've implemented an Application component that wraps its contents in an error boundary. A custom error is thrown from a subcomponent, and the custom typing gets lost somewhere along the way. That is, from the error boundary's perspective, the error that's thrown is of type
Error
, not the custom type defined in the application.Also on StackOverflow: https://stackoverflow.com/questions/48777152/how-do-i-work-with-custom-error-types-in-react-error-boundaries/48792418
The expected behavior is that custom error types would be preserved as they crossed error boundaries.
Tested in React/ReactDOM 16.2.0, in Chrome 63.0.3239.132, MacOS 10.12.6.
The text was updated successfully, but these errors were encountered: