UNPKG

@lomi./sdk

Version:

Official TypeScript SDK for the lomi. API

54 lines 1.4 kB
/** * HTTP Request Helper * AUTO-GENERATED - Do not edit manually */ import axios from 'axios'; import { OpenAPI } from './OpenAPI.js'; export class ApiError extends Error { constructor(response, message) { super(message); this.url = response.config.url || ''; this.status = response.status; this.statusText = response.statusText; this.body = response.data; } } function getUrl(options) { let url = `${OpenAPI.BASE}${options.url}`; if (options.path) { for (const [key, value] of Object.entries(options.path)) { url = url.replace(`{${key}}`, String(value)); } } return url; } function getHeaders(options) { const headers = { 'Content-Type': 'application/json', ...OpenAPI.HEADERS, ...options.headers, }; return headers; } export async function request(options) { const url = getUrl(options); const headers = getHeaders(options); const config = { method: options.method, url, headers, params: options.query, data: options.body, }; try { const response = await axios(config); return response.data; } catch (error) { if (error.response) { throw new ApiError(error.response, error.message); } throw error; } } //# sourceMappingURL=request.js.map