UNPKG

@gam-test/fetch-wrapper

Version:

A simple fetch wrapper for better error handling and less response context

2 lines 955 B
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunk3IRUMJMOjs = require('./chunk-3IRUMJMO.js');var n=class{constructor({url:t}){this.url=t}async request(t){let e=await this.connect(t);if(!("bodyParser"in t))return{status:e.status,headers:e.headers};if(!t.bodyParser)return{status:e.status,headers:e.headers};try{let r=await t.bodyParser(e);return{status:e.status,headers:e.headers,body:r}}catch(r){if(!(r instanceof Error))throw r;let a=await e.text().catch(async()=>{if(!e.body)return"No response body.";let s=await e.body.getReader().read().catch(()=>{});return s?new TextDecoder().decode(s.value):"Error getting response content"});throw new (0, _chunk3IRUMJMOjs.a)({url:this.url,content:_nullishCoalesce(a, () => ("Error getting response content")),cause:r})}}};exports.a = n; //# sourceMappingURL=chunk-M4G7TNUM.js.map