UNPKG

@donation-alerts/api-call

Version:
28 lines (27 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDonationAlertsApiResponseError = handleDonationAlertsApiResponseError; exports.transformDonationAlertsResponse = transformDonationAlertsResponse; const qs_1 = require("qs"); const http_error_1 = require("../errors/http.error"); /** @internal */ async function handleDonationAlertsApiResponseError(response, options) { if (!response.ok) { const isJson = response.headers.get('Content-Type') === 'application/json'; const text = isJson ? JSON.stringify(await response.json(), null, 2) : await response.text(); const params = (0, qs_1.stringify)(options.query, { arrayFormat: 'repeat', addQueryPrefix: true }); const fullUrl = `${options.url}${params}`; throw new http_error_1.HttpError(response.status, response.statusText, fullUrl, options.method ?? 'GET', text, isJson); } } /** @internal */ async function transformDonationAlertsResponse(response) { if (response.status === 204) { return undefined; } const text = await response.text(); if (!text) { return undefined; } return JSON.parse(text); }