Skip to content

Commit

Permalink
Improve user facing error message on invalid content-length
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jasnell committed May 10, 2024
1 parent c2a9157 commit 280c327
Showing 1 changed file with 7 additions and 1 deletion.
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());
}
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

0 comments on commit 280c327

Please sign in to comment.