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

Improve user facing error message on invalid content-length #2111

Merged
merged 1 commit into from
May 11, 2024

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented May 10, 2024

Previously an invalid content-length would result in an unhelpful "internal error" message to the user. This intercepts that error and replaces it with a more helpful message.

Longer term, it would be idea to align this more with the fetch spec but for now, improving the error message is a good first step.

Fixes: #2101

@jasnell jasnell requested review from a team as code owners May 10, 2024 21:06
@jasnell jasnell requested review from mikea and fhanau May 10, 2024 21:06
@jasnell jasnell added bug Something isn't working spec-compliance api labels May 10, 2024
Previously an invalid content-length would result in an unhelpful
"internal error" message to the user. This intercepts that error
and replaces it with a more helpful message.

Longer term, it would be idea to align this more with the fetch
spec but for now, improving the error message is a good first step.

Fixes: #2101
@jasnell jasnell force-pushed the jsnell/improve-invalid-content-length-error branch from fbdd696 to 280c327 Compare May 10, 2024 23:27
@jasnell jasnell merged commit 0219e89 into main May 11, 2024
10 checks passed
AbortSignal::maybeCancelWrap(signal, kj::mv(KJ_ASSERT_NONNULL(nativeRequest).response))
.catch_([](kj::Exception&& exception) -> kj::Promise<kj::HttpClient::Response> {
if (exception.getDescription().startsWith("invalid Content-Length header value")) {
return JSG_KJ_EXCEPTION(FAILED, Error, exception.getDescription());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell Minor point, but JavaScript error message style is usually more formal than KJ error message style, e.g. expecting complete sentences with a capitalized first letter and terminating punctuation.

On another note, I don't think it's possible for this error to happen in production since the invalid value would never get past FL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api bug Something isn't working spec-compliance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Bug Report — fetch response with multiple content-length values yields "internal error"
3 participants