import { Axios, AxiosError } from "axios"; import { Credentials, User, Flight } from "./Types"; const instance = new Axios({ baseURL: process.env.REACT_APP_ENDPOINT, headers: { accept: "application/json", "Content-Type": "application/json", }, validateStatus: (x) => { return !(x < 200 || x > 204) } }); instance.interceptors.response.use( (response) => { return JSON.parse(response.data); }, (error) => { const err = error as AxiosError; return Promise.reject(err); } ); instance.interceptors.request.use((request) => { request.data = JSON.stringify(request.data); return request; }); export const ping = () => { return instance.get("health"); }; export const fetchZones = (origin: string | undefined, lastUpdate: string | null): Promise => { return instance.get("flights" + (origin ? "?origin=" + origin : "") + (lastUpdate ? ( origin ? "&lastUpdated=" : "?lastUpdated=") + lastUpdate : "")) };