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

Improves error messages when fetch fails due to TLS errors. #3116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/workerd/api/http.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1962,10 +1962,11 @@ jsg::Promise<jsg::Ref<Response>> fetchImplNoOutputLock(jsg::Lock& js,
return ioContext.awaitIo(js,
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());
} else if (exception.getDescription().contains("NOSENTRY script not found")) {
if (exception.getDescription().contains("NOSENTRY script not found")) {
return JSG_KJ_EXCEPTION(FAILED, Error, "Worker not found.");
} else if (kj::str(exception.getFile()).startsWith("kj/")) {
return JSG_KJ_EXCEPTION(FAILED, Error,
kj::str("Internal error processing fetch: ", exception.getDescription()));
}
return kj::mv(exception);
}),
Expand Down
14 changes: 10 additions & 4 deletions src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,18 @@ kj::Maybe<jsg::Bundle::Reader> fetchPyodideBundle(

auto req = client->request(kj::HttpMethod::GET, url.asPtr(), headers);

auto res = req.response.wait(io.waitScope);
auto body = res.body->readAllBytes().wait(io.waitScope);
try {
auto res = req.response.wait(io.waitScope);
auto body = res.body->readAllBytes().wait(io.waitScope);

writePyodideBundleFileToDisk(pyConfig.pyodideDiskCacheRoot, version, body);
writePyodideBundleFileToDisk(pyConfig.pyodideDiskCacheRoot, version, body);

pyConfig.pyodideBundleManager.setPyodideBundleData(kj::str(version), kj::mv(body));
pyConfig.pyodideBundleManager.setPyodideBundleData(kj::str(version), kj::mv(body));
} catch (kj::Exception exc) {
// Without this the user would just see "internal error" with no additional info about
// what went wrong. Explicitly raising here gives the user a friendlier error message.
JSG_FAIL_REQUIRE(Error, kj::str("Failed to fetch Pyodide bundle: ", exc.getDescription()));
}
});
}

Expand Down
Loading