import axios , { AxiosRequestConfig , AxiosResponse } from 'axios' ; interface Response < T > { data : T ; } function mapResponse < T > ( response ) { return response . data ; } export const defaultHeaders = { 'accept' : 'application/json' , } ; export default async function fetchApi < T > ( endpoint , options ) { const baseUrl = process . env . REACT_APP_API_URL || '' ; return axios ( `${ baseUrl }${ endpoint }` , options ) . then ( ( response ) => { const responseData = response . data ? mapResponse < T > ( response ) : ( ( response as unknown ) as T ) ; return responseData ; } ) . catch ( ( error ) => { return { code : error . response . status , message : error . response . data . error , } ; } ) ; }