From c2a33992915fa7715ba829166aa98e33b7fe5a6a Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Fri, 31 Oct 2025 18:19:28 -0700 Subject: [PATCH] improve err handing --- .../pki-acme/pki-acme-challenge-service.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts index a7703f130..f9be0a60a 100644 --- a/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts +++ b/backend/src/ee/services/pki-acme/pki-acme-challenge-service.ts @@ -78,18 +78,12 @@ export const pkiAcmeChallengeServiceFactory = ({ // Properly type and inspect the error if (error instanceof TypeError && error.message.includes("fetch failed")) { const cause = error.cause; - if (cause instanceof Error) { - if (cause.message.includes("ECONNREFUSED")) { + const errors = cause instanceof AggregateError ? cause.errors : cause instanceof Error ? [cause] : []; + for (const err of errors) { + // TODO: handle multiple errors, return a compound error instead of just the first error + if (err?.code === "ECONNREFUSED" || err?.message?.includes("ECONNREFUSED")) { return new AcmeConnectionError({ message: "Connection refused" }); - } else if (cause.message.includes("ENOTFOUND")) { - return new AcmeDnsFailureError({ message: "Hostname could not be resolved (DNS failure)" }); - } - } else if (cause instanceof AggregateError) { - // TODO: handle multiple errors - const firstError = cause.errors?.[0]; - if (firstError?.code === "ECONNREFUSED") { - return new AcmeConnectionError({ message: "Connection refused" }); - } else if (firstError?.code === "ENOTFOUND") { + } else if (err?.code === "ENOTFOUND" || err?.message?.includes("ENOTFOUND")) { return new AcmeDnsFailureError({ message: "Hostname could not be resolved (DNS failure)" }); } }