You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

requestStatusMiddleware.js 846B

123456789101112131415161718192021222324252627
  1. import { attachPostRequestListener } from "../../request";
  2. import apiEndpoints from "../../request/apiEndpoints";
  3. import { logoutUser } from "../actions/login/loginActions";
  4. export const requestStatusMiddlewareInterceptorName =
  5. "REQUEST_STATUS_MIDDLEWARE_INTERCEPTOR";
  6. export default ({ dispatch }) =>
  7. (next) =>
  8. (action) => {
  9. attachPostRequestListener((error) => {
  10. if (!error.response) {
  11. return Promise.reject(error);
  12. }
  13. if (
  14. error.response.config.url !== apiEndpoints.authentications.login &&
  15. error.response.config.url !==
  16. apiEndpoints.authentications.confirmSecurityQuestion &&
  17. error.response.status === 401
  18. ) {
  19. return dispatch(logoutUser());
  20. }
  21. return Promise.reject(error);
  22. }, requestStatusMiddlewareInterceptorName);
  23. next(action);
  24. };