Skip to content
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

catch error in fall back to utf8 #2336

Merged
merged 3 commits into from Mar 7, 2024
Merged

Conversation

archvlad
Copy link
Contributor

@archvlad archvlad commented Mar 3, 2024

To reproduce error fetch big file and then read body of the response. You will receive the error but you won't be able to catch it with try-catch.

import got from "got";

try {
  const res = await got("https://mp4-download.com/8k-5-MP4");
  console.log(res.body);
} catch (error) {
  console.log("Catch error:", error.message);
}

So what I add is try-catch block to response.rawBody.toString() as it is in parseBody method from got\dist\source\core\response.js

Checklist

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.
  • If it's a new feature, I have included documentation updates in both the README and the types.

@archvlad archvlad force-pushed the main branch 2 times, most recently from 3e248ea to 42cd8ee Compare March 3, 2024 20:30
@sindresorhus
Copy link
Owner

This needs a test.

@archvlad archvlad force-pushed the main branch 5 times, most recently from b0a9c81 to 4a219ef Compare March 5, 2024 19:30
@archvlad
Copy link
Contributor Author

archvlad commented Mar 5, 2024

The problem occurred when I get a body larger than 512MB, causing Buffer.toString() to throw an error. So, I added test that creates buffer with size 512 MB and then sends it to the client.

@sindresorhus sindresorhus merged commit c81a611 into sindresorhus:main Mar 7, 2024
1 check passed
@archvlad
Copy link
Contributor Author

archvlad commented Mar 8, 2024

Thank you for accepting my PR. I have little experience in participating in open source, so this is very valuable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants