Skip to content

Commit

Permalink
Improves error messages when fetch fails due to TLS errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Nov 14, 2024
1 parent 12479a1 commit f16eb43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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

0 comments on commit f16eb43

Please sign in to comment.