import { HttpSetup , HttpFetchQuery } from '../../../../core/public' ; export interface SendRequestConfig { path : string ; method : 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' ; query ? : HttpFetchQuery ; body ? : any ; } export interface SendRequestResponse < D = any , E = any > { data : D | null ; error : E | null ; } export const sendRequest = async < D = any , E = any > ( httpClient , { path , method , body , query } ) : Promise < SendRequestResponse < D , E > > => { try { const stringifiedBody = typeof body === 'string' ? body : JSON . stringify ( body ) ; const response = await httpClient [ method ] ( path , { body : stringifiedBody , query } ) ; return { data : response . data ? response . data : response , error : null , } ; } catch ( e ) { return { data : null , error : e . response ?. data ?? e . body , } ; } } ;