-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CloudFlare workers Response.type workaround #159
Comments
Hey @jimmed 👋
Thanks for reporting the issue - and for the kind words! ❤️
Since this is a very specific use case and it seems like the CF implementation differs from the standard (which is never supposed to throw) I would prefer not to change the code. So I added a new |
Hi @jimmed, I'm testing wretch on CloudFlare and it throws the same error when using the middleware.
|
@yanielblanco are you using the CloudFlare service worker format, or module worker format? I don't know if it makes any difference, but I'm running that middleware via the service worker format. |
@jimmed Hi, thanks for your fast answer. I'm using service worker format. My issue happened when try to define property. In this moment I think that invoke property type and throw unimplemented error of worker that you comment here #159 (comment). I am new working with workers 😅. Thanks for your help. |
I'm not sure what to suggest -- the exact middleware code I included in the original post is currently running in production in CF workers, and works perfectly for me. |
@jimmed Thanks 😅 |
@elbywan Is it possible to add validation for cloudflare before calling the type property? I know you don't like to modify the code because it's a very specific case but I want to keep using wretch because it's awesome. I created a fork and I added a try catch block around response.type.
|
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'stype
property.wretch/src/resolver.ts
Lines 52 to 54 in c1fc7a6
Unfortunately, CF's
Response
implementation defines a getter fortype
, which throws an error, as they don't implement this field (given it's a server runtime, not a browser).https://github.com/cloudflare/miniflare/blob/9d96aaa66aa48eb1107c86fe24cbfd444249533c/packages/core/src/standards/http.ts#L637-L639
To work around this, I wrote a small middleware:
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.
The text was updated successfully, but these errors were encountered: