afterResponse hook stops response from resolving
See original GitHub issueRepro — https://github.com/paambaati/ky-body-timeout-repro
I use ky
and ky-universal
in a Next.js app and I noticed responses failing with a body-timeout
error on the Node.js side only for responses above roughly 50KB in size. I’ve tried tweaking the highWatermark
and size
options, but it doesn’t seem to have an effect.
I have an afterResponse
hook that does some additional stuff like logging the responses, redirecting to my login page if the response is a 401
, etc.
If I remove the hook, it works. This is illustrated in my repro where I’ve added a hook with just one console.log
statement, and you can see the issue occurring. Returning the res
has no effect. If the hook is completely removed on the repro, it works.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Execute a function after Flask returns response - Stack Overflow
In most cases, the best way to solve this problem is to use a task ... Flask("after_response") AfterResponse(app) @app.after_response def ...
Read more >got - npm
afterResponse. Type: Function[] Default: []. Note: When using streams, this hook is ignored. Called with response object and a retry ...
Read more >ky@v0.31.0 | Deno
This hook enables you to read and optionally modify the response. The hook function receives normalized request, options, and a clone of the...
Read more >How to use the got.extend function in got - Snyk
url} fail, retry attempt #${count}: ${err}`); }, ], afterResponse: [ (response) => { try { response.data = JSON.parse(response.body); } catch (e) { response....
Read more >Zapier Platform CLI Docs
targetUrl has the Hook URL this app should call }, }; const response ... you need send a DELETE request to your server...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m willing to target the beta.
You need to avoid using the three features I mentioned in the linked issue. Each of those features clone the response, which triggers the bug. Using body method shorthands is only one of the relevant features, so using the verbose syntax won’t fix your code on it’s own, as you are still using an
afterResponse
hook.Needless to say, it’s a major issue, hence the bounty attached to it.
If you cannot modify your code to avoid using those features, then my recommendation is to fork Ky and update the
node-fetch
dependency in package.json to use the v3 beta. If you end up doing that, feel free to submit a PR. Otherwise, I’ll take care of it myself within the next few days.