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

catch error in fall back to utf8 #2336

merged 3 commits into from
Mar 7, 2024

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.

@sindresorhus
Copy link
Owner

This needs a test.

@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.

Vylpes pushed a commit to Vylpes/random-bunny that referenced this pull request Sep 2, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [got](https://github.com/sindresorhus/got) | resolutions | minor | [`14.0.0` -> `14.4.2`](https://renovatebot.com/diffs/npm/got/14.0.0/14.4.2) |

---

### Release Notes

<details>
<summary>sindresorhus/got (got)</summary>

### [`v14.4.2`](https://github.com/sindresorhus/got/releases/tag/v14.4.2)

[Compare Source](sindresorhus/got@v14.4.1...v14.4.2)

-   Fix handling of invalid arguments ([#&#8203;2367](sindresorhus/got#2367))  [`f44ef43`](sindresorhus/got@f44ef43)

### [`v14.4.1`](https://github.com/sindresorhus/got/releases/tag/v14.4.1)

[Compare Source](sindresorhus/got@v14.4.0...v14.4.1)

-   Fix missing dependency  [`dfc54d9`](sindresorhus/got@dfc54d9)

### [`v14.4.0`](https://github.com/sindresorhus/got/releases/tag/v14.4.0)

[Compare Source](sindresorhus/got@v14.3.0...v14.4.0)

-   Improve TypeScript types with generic extend ([#&#8203;2353](sindresorhus/got#2353))  [`15ca4a0`](sindresorhus/got@15ca4a0)

### [`v14.3.0`](https://github.com/sindresorhus/got/releases/tag/v14.3.0)

[Compare Source](sindresorhus/got@v14.2.1...v14.3.0)

-   Update dependencies  [`dbab6c3`](sindresorhus/got@dbab6c3)

### [`v14.2.1`](https://github.com/sindresorhus/got/releases/tag/v14.2.1)

[Compare Source](sindresorhus/got@v14.2.0...v14.2.1)

-   Fix error handling when UTF-8 decoding fails ([#&#8203;2336](sindresorhus/got#2336))  [`c81a611`](sindresorhus/got@c81a611)

### [`v14.2.0`](https://github.com/sindresorhus/got/releases/tag/v14.2.0)

[Compare Source](sindresorhus/got@v14.1.0...v14.2.0)

-   Add `cause` property with the original error to `RequestError` ([#&#8203;2327](sindresorhus/got#2327))  [`4cbd01d`](sindresorhus/got@4cbd01d)

### [`v14.1.0`](https://github.com/sindresorhus/got/releases/tag/v14.1.0)

[Compare Source](sindresorhus/got@v14.0.0...v14.1.0)

-   Allow typing the body of a `RequestError` response ([#&#8203;2325](sindresorhus/got#2325))  [`5e4f6ff`](sindresorhus/got@5e4f6ff)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMS40IiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJ0eXBlL2RlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.vylpes.xyz/RabbitLabs/random-bunny/pulls/217
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
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.

2 participants