forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-client.ts
More file actions
41 lines (36 loc) · 974 Bytes
/
Copy pathapi-client.ts
File metadata and controls
41 lines (36 loc) · 974 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
import axios, { type InternalAxiosRequestConfig } from "axios";
import {
API_TIMEOUT,
BASE_API_URL,
DEFAULT_API_REQUEST_ERROR,
DEFAULT_NETWORK_CONNECTIVITY_ERROR,
} from "../constants/api";
function createApiClient(baseURL: string) {
const apiInstance = axios.create({
baseURL,
timeout: API_TIMEOUT,
headers: {
"Content-Type": "application/json",
},
});
apiInstance.interceptors.request.use(
async (config: InternalAxiosRequestConfig) => {
return config;
},
);
apiInstance.interceptors.response.use(
async (response) => {
return response;
},
async (error) => {
return Promise.reject(
error.response?.data?.message ||
DEFAULT_API_REQUEST_ERROR ||
DEFAULT_NETWORK_CONNECTIVITY_ERROR,
);
},
);
return apiInstance;
}
// Export an API client instance - e.g. stellarSplitApiClient('/stellar-split')
export const apiClient = createApiClient(BASE_API_URL);