I have the following code in index.tsx:
window.onerror = function(msg, url, line, col, error) {
   debugger;
   // Note that col & error are new to the HTML 5 spec and may not be 
   // supported in every browser.  It worked for me in Chrome.
   var extra = !col ? '' : '\ncolumn: ' + col;
   extra += !error ? '' : '\nerror: ' + error;
   // You can view the information in an alert to see things working like this:
   alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
   // TODO: Report this error via ajax so you can keep track
   //       of what pages have JS issues
   var suppressErrorAlert = true;
   // If you return true, then error alerts (like in older versions of 
   // Internet Explorer) will be suppressed.
   return suppressErrorAlert;
};
Source:
https://stackoverflow.com/a/10556743/3850405
If I throw an error like this in another component I will catch it as expected:
componentDidMount() {
    throw new Error();
}
If thrown like this:
async componentDidMount() {
    throw new Error();
}
The error is not catched and an Unhandled Rejection (Error): is shown.
I then tried to create a React global error boundary.
import React, { ErrorInfo } from 'react';
interface IProps {
}
interface IState {
    hasError: boolean
}
class ErrorBoundary extends React.PureComponent<IProps, IState> {
    constructor(props: IProps) {
        super(props);
        this.state = { hasError: false };
    }
    componentDidCatch(error: Error, info: ErrorInfo) {
        // Display fallback UI
        debugger;
        console.warn(error);
        console.warn(info);
        this.setState({ hasError: true });
        // You can also log the error to an error reporting service
        //logErrorToMyService(error, info);
    }
    render() {
        if (this.state.hasError) {
            // You can render any custom fallback UI
            return <h1>Something went wrong.</h1>;
        }
        return this.props.children;
    }
}
export default ErrorBoundary
index.tsx:
<React.StrictMode>
    <Provider store={store}>
        <ConnectedIntlProvider>
            <Router>
                <ErrorBoundary>
                    <App />
                </ErrorBoundary>
            </Router>
        </ConnectedIntlProvider>
    </Provider>
</React.StrictMode>,
Sources:
https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html
https://stackoverflow.com/a/51764435/3850405
The effect was however the same, async componentDidMount was not caught but otherwise it worked as expected.
I have found this thread that mentions the problem but no real solution.
https://stackoverflow.com/a/56800470/3850405
How can I create a global error handler in React that really catches everything?



