@gam-test/fetch-wrapper
Version:
A simple fetch wrapper for better error handling and less response context
2 lines • 725 B
JavaScript
import{a as o}from"./chunk-3IRUMJMO.js";var n=class{url;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 o({url:this.url,content:a??"Error getting response content",cause:r})}}};export{n as a};
//# sourceMappingURL=chunk-M4G7TNUM.js.map