-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttpService.js
More file actions
45 lines (37 loc) · 922 Bytes
/
Copy pathhttpService.js
File metadata and controls
45 lines (37 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import axios from 'axios';
import { ToastAndroid } from 'react-native';
import { store } from 'store';
const http = axios.create({
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
http.interceptors.request.use(config => {
const state = store.getState();
if (state?.Auth?.idToken) {
const token = `Bearer ${state.Auth.idToken}`;
config.headers.Authorization = token;
}
return config;
});
http.interceptors.response.use(null, error => {
if (error?.response?.data?.message) {
ToastAndroid.showWithGravity(
error.response.data.message,
ToastAndroid.SHORT,
ToastAndroid.TOP,
);
return { error };
}
if (error?.response?.message) {
ToastAndroid.showWithGravity(
error.response.message,
ToastAndroid.SHORT,
ToastAndroid.TOP,
);
return { error };
}
return { error };
});
export default http;