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

atlp-rwanda / hackers-ec-Fe / #1136

23 Jul 2024 01:45PM UTC coverage: 92.72% (-0.004%) from 92.724%
#1136

Pull #44

Angemichel12
feat:(stripe payment): implementation of stripe payment 187419028
Pull Request #44: #187419028 implementation of stripe payment API

753 of 926 branches covered (81.32%)

Branch coverage included in aggregate %.

342 of 357 new or added lines in 8 files covered. (95.8%)

3 existing lines in 2 files now uncovered.

8634 of 9198 relevant lines covered (93.87%)

15.92 hits per line

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

93.65
/src/utils/api.ts
1
import axios, {
1✔
2
        AxiosInstance,
1✔
3
        AxiosResponse,
1✔
4
        AxiosError,
1✔
5
        InternalAxiosRequestConfig,
1✔
6
} from 'axios';
1✔
7

1✔
8
import { toast } from 'sonner';
1✔
9

1✔
10
const API: AxiosInstance = axios.create({
1✔
11
        baseURL: `${import.meta.env.VITE_API_BASE_URL}`,
1✔
12
        timeout: 50000,
1✔
13
        headers: {},
1✔
14
});
1✔
15

1✔
16
const requestHandler = (
1✔
17
        config: InternalAxiosRequestConfig,
166✔
18
): InternalAxiosRequestConfig => {
166✔
19
        const token = localStorage.getItem('access_token') || '';
166✔
20
        config.headers = config.headers || {};
166!
21
        config.headers.Authorization = `Bearer ${token}`;
166✔
22
        return config;
166✔
23
};
166✔
24

1✔
25
const responseHandler = (response: AxiosResponse): AxiosResponse => response;
1✔
26

1✔
27
const errorHandler = (error: AxiosError): Promise<never> => {
1✔
28
        if (error.response?.status === 401) {
15✔
29
                localStorage.clear();
10✔
30
                window.location.href = '/login';
10✔
31
        } else if (error.message === 'Request failed with status code 403') {
14✔
32
                toast.error('Password outdated, Update it!');
4✔
33
        } else if (error.message === 'Network Error') {
5!
34
                toast.error('Network Error: Connect to Server');
×
UNCOV
35
        }
×
36
        return Promise.reject(error);
15✔
37
};
15✔
38

1✔
39
API.interceptors.request.use(
1✔
40
        (config: InternalAxiosRequestConfig) => requestHandler(config),
1✔
41
        (error: AxiosError) => errorHandler(error),
1✔
42
);
1✔
43

1✔
44
API.interceptors.response.use(
1✔
45
        (response: AxiosResponse) => responseHandler(response),
1✔
46
        (error: AxiosError) => errorHandler(error),
1✔
47
);
1✔
48

1✔
49
export default API;
1✔
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

© 2025 Coveralls, Inc