mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 18:27:19 +00:00
Better error handling
This commit is contained in:
@@ -77,13 +77,21 @@ export const pkiAcmeChallengeServiceFactory = ({
|
|||||||
await acmeChallengeDAL.markAsInvalidCascadeById(challengeId, tx);
|
await acmeChallengeDAL.markAsInvalidCascadeById(challengeId, tx);
|
||||||
// Properly type and inspect the error
|
// Properly type and inspect the error
|
||||||
if (error instanceof TypeError && error.message.includes("fetch failed")) {
|
if (error instanceof TypeError && error.message.includes("fetch failed")) {
|
||||||
const cause = error.cause as AggregateError;
|
const cause = error.cause;
|
||||||
if (cause?.errors?.[0]?.code === "ECONNREFUSED") {
|
if (cause instanceof Error) {
|
||||||
logger.error(error, "Connection refused.");
|
if (cause.message.includes("ECONNREFUSED")) {
|
||||||
return new AcmeConnectionError({ message: "Connection refused." });
|
return new AcmeConnectionError({ message: "Connection refused" });
|
||||||
} else if (cause?.errors?.[0]?.code === "ENOTFOUND") {
|
} else if (cause.message.includes("ENOTFOUND")) {
|
||||||
logger.error(error, "Hostname could not be resolved (DNS failure).");
|
return new AcmeDnsFailureError({ message: "Hostname could not be resolved (DNS failure)" });
|
||||||
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") {
|
||||||
|
return new AcmeDnsFailureError({ message: "Hostname could not be resolved (DNS failure)" });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (error instanceof Error) {
|
} else if (error instanceof Error) {
|
||||||
logger.error(error, "Error validating ACME challenge response");
|
logger.error(error, "Error validating ACME challenge response");
|
||||||
|
|||||||
Reference in New Issue
Block a user