• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlp-rwanda / eagles-ec-fe / 9977852221

17 Jul 2024 04:21PM UTC coverage: 67.632% (+1.2%) from 66.427%
9977852221

push

github

web-flow
Merge pull request #25 from atlp-rwanda/ft-Intercept-Axios-#187790848

#187790848 Set up Axios interceptors for Network errors, 401 Errors and redirections

143 of 308 branches covered (46.43%)

Branch coverage included in aggregate %.

15 of 24 new or added lines in 3 files covered. (62.5%)

1 existing line in 1 file now uncovered.

908 of 1246 relevant lines covered (72.87%)

6.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.17
/src/redux/api/api.ts
1
import { set } from "react-hook-form";
2
import { useState, useEffect } from "react";
3
import { toast } from "react-toastify";
46✔
4

5
import store from "../store";
6

7
import api from "./action";
46✔
8

9
let navigateFunction = null;
46✔
10

11
export const setNavigateFunction = (navigate) => {
46✔
NEW
12
  navigateFunction = navigate;
×
13
};
14
const redirectToLogin = (navigate) => {
46✔
NEW
15
  setTimeout(() => {
×
NEW
16
    navigate("/login");
×
17
  }, 2000);
18
};
19

20
api.interceptors.response.use(
46✔
21
  (response) => response,
10✔
22
  (error) => {
23
    const excludeRoute = "/";
14✔
24

25
    if (
14!
26
      error.response
12!
27
      && error.response.status === 401
28
      && window.location.pathname !== excludeRoute
29
    ) {
NEW
30
      if (navigateFunction) {
×
NEW
31
        toast("Login is Required for this action \n Redirecting to Login \n ");
×
NEW
32
        setTimeout(() => {
×
NEW
33
          redirectToLogin(navigateFunction);
×
34
        }, 2000);
35
      }
36
    }
37
    return Promise.reject(error);
14✔
38
  },
39
);
40

41
export default api;
46✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc