import axios from "axios"; import { HttpRequestOptions, HttpResponse } from "./../../types"; import { getLogString } from "@putkoff/abstract-logger"; import {normalizeHeaders} from './../shared'; export async function httpServer( method: string, url: string, body: any, options: HttpRequestOptions = {}, ): 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( `HTTP Server Error ${JSON.stringify({ url, method, error: error instanceof Error ? error.message : String(error), })}`, ); throw error; } }