UNPKG

http-service-lib

Version:

Reusable Http Service and implementations

27 lines (26 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FetchHttpDeleteService = void 0; const HttpResponse_1 = require("../../../entities/HttpResponse"); const HttpError_1 = require("../../../errors/HttpError"); const FetchHttpService_1 = require("./FetchHttpService"); class FetchHttpDeleteService extends FetchHttpService_1.FetchHttpService { async delete(request) { try { const response = await fetch(request.url, { headers: request.headers, method: 'DELETE', credentials: 'include', }); if (!response.ok) throw new HttpError_1.HttpError(await response.text(), response.status); return new HttpResponse_1.HttpResponse(response.status, await this.parseResponseBody(response)); } catch (error) { if (error instanceof HttpError_1.HttpError) throw error; throw new HttpError_1.HttpError('Could not reach endpoint', 404); } } } exports.FetchHttpDeleteService = FetchHttpDeleteService;