I am using this react redux starter, I would like to know how I can redirect all api 500 errors to a page please?
Asked
Active
Viewed 2,532 times
3
-
Can you catch the error in front-end? If you can, push to the history with the page you wants direct to. You can check out implementation details in react-router's documents. – David Guan Jun 13 '16 at 09:06
1 Answers
0
redux-starter has react-router-redux
and redux-thunk
installed by default.
I'm unsure of where the API calls are made since you didn't provide any code but if you can inject the store into your API wrapper perhaps you can dispatch a router action via your redux store.
Assuming you are using some kind of API wrapper and thunks you can do something like this:
import { push } from 'react-router-redux';
function myThunkFunction() {
return dispatch => axios.get(...).catch((error) => {
/** insert logic to determine 500 error **/
if (500error) {
dispatch(push('http://example.com/error/500'));
}
});
}

l0gicgate
- 183
- 5