UNPKG

simple-fetch-ts

Version:

`simple-fetch-ts` is a TypeScript library designed to simplify HTTP requests using a builder-pattern approach. It provides a fluent API for creating, configuring, and executing various HTTP methods (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`) with type safet

34 lines (33 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tsDelete = void 0; const request_error_1 = require("../../errors/request-error"); const tsDelete = async (url, requestHeaders = {}, signal) => { try { const response = await fetch(url, { method: "DELETE", headers: { ...requestHeaders }, signal, }); if (!response.ok) { const errorText = await response .text() .catch(() => "Unable to parse response text"); throw new request_error_1.SimpleFetchRequestError("DELETE", url, response.status, response.statusText, errorText); } const data = await response.json(); return { data, status: response.status, headers: response.headers, raw: response, }; } catch (error) { if (error instanceof request_error_1.SimpleFetchRequestError) { throw error; } throw new Error(error instanceof Error ? error.message : "An unknown error occurred"); } }; exports.tsDelete = tsDelete;