I'm trying to add global error logging using window.onerror
as outlined in the accepted answer of this question.
I have it working when I throw an error in one of my component lifecycle methods and synchronous redux actions. However, errors thrown from an async thunk
action do NOT get caught by my handler.
Is this expected? Is there some way I can catch these errors in a global handler?
export const syncReduxAction = (): Action => {
throw 'This will trigger window.onerror';
};
export const asyncReduxAction = (): ThunkAction<Promise<T>, GlobalState, void> =>
async (dispatch, getState) => {
throw 'This will NOT trigger window.onerror';
}
Update
According to this question, it looks like async errors are in fact not handled by the window.onerror
event handler.
But even if I catch the error and rethrow it:
this.props.dispatch(asyncReduxAction())
.catch((e)=> {
throw new Error(e);
}
);
It doesn't trigger the event!