import { HttpRequestOptions, HttpResponse, axios, withRetry, getLogString, } from "./imports"; import { normalizeHeaders } from "../shared"; export async function axiosRequest( method: string, url: string, body?: any, options: HttpRequestOptions = {}, ): Promise> { const exec = async (): Promise> => { try { const res = await axios({ method, url, data: body, timeout: options.timeout ?? 8000, headers: { ...(options.headers || {}) }, }); return { status: res.status, data: res.data, headers: normalizeHeaders(res.headers), }; } catch (error: unknown) { getLogString( `Axios HTTP Error ${JSON.stringify({ url, method, error: error instanceof Error ? error.message : String(error), })}`, ); throw error; } }; return withRetry(exec, options.retry); }