import axios, { AxiosResponse } from "axios"; interface RequestResponse { response: AxiosResponse | null; data: T | null; error: any; } const request = { async safe(funcCall: any, url: string, data: object = {}): Promise> { const response = await funcCall(url, data).catch(function (error: object) { console.log(error); // Insert Generic Error Handling Here return { response: null, error, data: null }; }); return { response, error: null, data: response.data }; }, }; export const requests = { async get(url: string, queryParams = {}): Promise> { let error = null; const response = await axios.get(url, { params: { queryParams } }).catch((e) => { error = e; }); if (response != null) { return { response, error, data: response?.data }; } return { response: null, error, data: null }; }, async post(url: string, data: object) { return await request.safe(axios.post, url, data); }, async put(url: string, data: object) { return await request.safe(axios.put, url, data); }, async patch(url: string, data: object) { return await request.safe(axios.patch, url, data); }, async delete(url: string) { return await request.safe(axios.delete, url); }, };