-
-
Notifications
You must be signed in to change notification settings - Fork 102
Closed
Labels
Description
I've been using wretch for a few years now, and I absolutely adore it!
Recently I started using it in the CloudFlare Workers runtime. I noticed that when handling a non-ok
response, wretch attempts to access the response's type
property.
Lines 52 to 54 in c1fc7a6
if (response.type === "opaque") { | |
throw err | |
} |
Unfortunately, CF's Response
implementation defines a getter for type
, which throws an error, as they don't implement this field (given it's a server runtime, not a browser).
To work around this, I wrote a small middleware:
wretch().middlewares([
(next) => async (url, opts) => {
const response = await next(url, opts);
try {
Reflect.get(response, "type", response);
} catch (error) {
Object.defineProperty(response, "type", {
get: () => "default",
});
}
return response;
},
])
I'm not sure whether you would prefer to add this to wretch's documentation somewhere, or change wretch's error handling logic such that it catches these errors from CF.
hmnd