Remove superfluous error handling details

This commit is contained in:
Michael B. Gale
2026-02-10 17:15:03 +00:00
parent 51357000d2
commit c4b0f60beb
3 changed files with 11 additions and 28 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ test("checkConnections - excludes failed status codes", async (t) => {
sinon
.stub(backend, "checkConnection")
.onSecondCall()
.throws(new ReachabilityError(nugetFeed, 400));
.throws(new ReachabilityError(400));
const messages = await withRecordingLoggerAsync(async (logger) => {
const reachable = await checkConnections(logger, proxyInfo, backend);
t.is(reachable.size, 1);
+5 -15
View File
@@ -5,20 +5,11 @@ import { HttpsProxyAgent } from "https-proxy-agent";
import { Logger } from "../logging";
import { getErrorMessage } from "../util";
import { getAddressString, ProxyInfo, Registry, ValidRegistry } from "./types";
import { getAddressString, ProxyInfo, ValidRegistry } from "./types";
export class ReachabilityError extends Error {
constructor(
public readonly registry: Registry,
public readonly statusCode?: number | undefined,
) {
const statusStr = ReachabilityError.getStatusStr(statusCode);
super(`Connection test to ${registry.url} failed.${statusStr}`);
}
private static getStatusStr(statusCode: number | undefined) {
if (statusCode === undefined) return "";
return ` (${statusCode})`;
constructor(public readonly statusCode?: number | undefined) {
super();
}
}
@@ -63,13 +54,12 @@ class NetworkReachabilityBackend implements ReachabilityBackend {
if (res.statusCode !== undefined && res.statusCode < 400) {
resolve(res.statusCode);
} else {
reject(new ReachabilityError(registry, res.statusCode));
reject(new ReachabilityError(res.statusCode));
}
},
);
req.on("error", (e) => {
this.logger.error(e);
reject(new ReachabilityError(registry));
reject(e);
});
req.end();
});