diff --git a/src/workerd/api/http.c++ b/src/workerd/api/http.c++ index 9fd77638e14..1930b20084c 100644 --- a/src/workerd/api/http.c++ +++ b/src/workerd/api/http.c++ @@ -1962,10 +1962,11 @@ jsg::Promise> fetchImplNoOutputLock(jsg::Lock& js, return ioContext.awaitIo(js, AbortSignal::maybeCancelWrap(signal, kj::mv(KJ_ASSERT_NONNULL(nativeRequest).response)) .catch_([](kj::Exception&& exception) -> kj::Promise { - 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); }), diff --git a/src/workerd/server/workerd-api.c++ b/src/workerd/server/workerd-api.c++ index a0dcf2df17a..ee2d666512e 100644 --- a/src/workerd/server/workerd-api.c++ +++ b/src/workerd/server/workerd-api.c++ @@ -507,12 +507,18 @@ kj::Maybe 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())); + } }); }