question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

afterResponse hook stops response from resolving

See original GitHub issue

Repro — 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.

CC: @sindresorhus, @sholladay, @szmarczak

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sindresorhuscommented, May 4, 2020

I’m willing to target the beta.

0reactions
sholladaycommented, May 5, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found