Replies: 1 comment 1 reply
-
This seems mostly correct— class ErrorBoundary extends React.Component<any> {
state = { error: null };
componentDidCatch(error) {
this.setState({ error });
}
componentDidMount() {
maybeRedirectToLogin();
}
componentDidUpdate() {
maybeRedirectToLogin();
}
maybeRedirectToLogin() {
const { router } = this.props;
const { asPath } = router;
const { error } = this.state;
if (error && error instanceof RRNLRequestError && error.res.status == 401) {
Router.push(`/login?redirect=${asPath}`);
}
}
render() {
const { children, fallback } = this.props;
const { error } = this.state;
if (error) {
return React.createElement(fallback, { error });
}
return children;
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I need to redrect to login page if a 401 error is catched. I did this with React error boundary. the
Router.push
is not supposed to be used imperatively.Beta Was this translation helpful? Give feedback.
All reactions