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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/workerd/api/http.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,13 @@ jsg::Promise<jsg::Ref<Response>> fetchImplNoOutputLock(
nativeRequest = client->request(jsRequest->getMethodEnum(), url, headers, uint64_t(0));
}
return ioContext.awaitIo(js,
AbortSignal::maybeCancelWrap(signal, kj::mv(KJ_ASSERT_NONNULL(nativeRequest).response)),
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.

}
return kj::mv(exception);
}),
[fetcher = kj::mv(fetcher), jsRequest = kj::mv(jsRequest),
urlList = kj::mv(urlList), client = kj::mv(client)]
(jsg::Lock& js, kj::HttpClient::Response&& response) mutable
Expand Down
Loading