const CODE_DESCRIPTIONS = {
  ENOTFOUND: { reason: "DNS resolution failed (ENOTFOUND)", hint: "Check the domain name; the host could not be resolved" },
  ECONNREFUSED: { reason: "Connection refused (ECONNREFUSED)", hint: "Target host rejected the connection \u2014 server may be down or port closed" },
  ECONNRESET: { reason: "Connection reset (ECONNRESET)", hint: "Remote peer closed the connection mid-request \u2014 retry may succeed" },
  ETIMEDOUT: { reason: "Connection timed out (ETIMEDOUT)", hint: "Increase timeoutMs or check network reachability" },
  EAI_AGAIN: { reason: "DNS lookup temporarily failed (EAI_AGAIN)", hint: "DNS resolver issue \u2014 retry shortly" },
  EHOSTUNREACH: { reason: "Host unreachable (EHOSTUNREACH)" },
  ENETUNREACH: { reason: "Network unreachable (ENETUNREACH)" },
  CERT_HAS_EXPIRED: { reason: "TLS certificate expired" },
  UNABLE_TO_VERIFY_LEAF_SIGNATURE: { reason: "TLS chain verification failed" },
  SELF_SIGNED_CERT_IN_CHAIN: { reason: "Self-signed TLS certificate in chain" }
};
function extractCode(err, depth = 0) {
  if (!err || depth > 5) return null;
  if (typeof err !== "object") return null;
  const e = err;
  if (typeof e.code === "string" && e.code) return e.code;
  if (e.cause) return extractCode(e.cause, depth + 1);
  return null;
}
function describeFetchError(err) {
  const code = extractCode(err);
  if (code && CODE_DESCRIPTIONS[code]) return CODE_DESCRIPTIONS[code];
  if (err instanceof Error) {
    if (err.name === "TimeoutError" || err.name === "AbortError") {
      return { reason: "Request timed out", hint: "Increase timeoutMs or check network reachability" };
    }
    const msg = err.message;
    if (code) return { reason: `${msg} (${code})` };
    return { reason: msg || "fetch failed" };
  }
  return { reason: String(err) };
}
export {
  describeFetchError
};
//# sourceMappingURL=error-describe.js.map