Mirror of https://github.com/roostorg/osprey github.com/roostorg/osprey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 26 lines 817 B view raw
1import axios, { AxiosError, AxiosResponse } from 'axios'; 2 3import useErrorStore from '../stores/ErrorStore'; 4 5const API_BASE_URL = process.env.REACT_APP_API_BASE_URL; 6const CORS_HEADER = { 'Access-Control-Allow-Origin': '*' }; 7 8const axiosInstance = axios.create({ 9 baseURL: API_BASE_URL, 10 headers: CORS_HEADER, 11}); 12 13export type HTTPResponse = (AxiosResponse & { ok: true }) | { ok: false; error: AxiosError<any> }; 14 15const errorHandler = (error: AxiosError<any>): HTTPResponse => { 16 if (error.response != null) { 17 const { errors } = useErrorStore.getState(); 18 useErrorStore.setState({ errors: new Set([...errors, error.response.data]) }); 19 } 20 21 return { ok: false, error }; 22}; 23 24axiosInstance.interceptors.response.use((response) => ({ ...response, ok: true }), errorHandler); 25 26export default axiosInstance;