From a501f100a774f8b382b0844fb7cdd168b90c4a31 Mon Sep 17 00:00:00 2001 From: Marcos Nocetti Date: Sat, 25 Apr 2026 13:24:10 -0300 Subject: [PATCH] feat: add ECONNREFUSED error code constant to AxiosError (#10680) Adds `AxiosError.ECONNREFUSED` as a typed constant alongside existing error codes like ECONNABORTED and ETIMEDOUT, enabling type-safe error code checks without hardcoding strings. Closes #6485 Co-authored-by: marcosnocetti Co-authored-by: Jay --- index.d.cts | 1 + index.d.ts | 1 + lib/core/AxiosError.js | 1 + 3 files changed, 3 insertions(+) diff --git a/index.d.cts b/index.d.cts index b3839a8e..5afd23e9 100644 --- a/index.d.cts +++ b/index.d.cts @@ -162,6 +162,7 @@ declare class AxiosError extends Error { static readonly ERR_CANCELED = 'ERR_CANCELED'; static readonly ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED'; static readonly ECONNABORTED = 'ECONNABORTED'; + static readonly ECONNREFUSED = 'ECONNREFUSED'; static readonly ETIMEDOUT = 'ETIMEDOUT'; } diff --git a/index.d.ts b/index.d.ts index 4fb2f8ee..4bcfe9e4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -519,6 +519,7 @@ export class AxiosError extends Error { static readonly ERR_CANCELED = 'ERR_CANCELED'; static readonly ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED'; static readonly ECONNABORTED = 'ECONNABORTED'; + static readonly ECONNREFUSED = 'ECONNREFUSED'; static readonly ETIMEDOUT = 'ETIMEDOUT'; } diff --git a/lib/core/AxiosError.js b/lib/core/AxiosError.js index 581004d2..882bcfb5 100644 --- a/lib/core/AxiosError.js +++ b/lib/core/AxiosError.js @@ -78,6 +78,7 @@ AxiosError.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE'; AxiosError.ERR_BAD_OPTION = 'ERR_BAD_OPTION'; AxiosError.ECONNABORTED = 'ECONNABORTED'; AxiosError.ETIMEDOUT = 'ETIMEDOUT'; +AxiosError.ECONNREFUSED = 'ECONNREFUSED'; AxiosError.ERR_NETWORK = 'ERR_NETWORK'; AxiosError.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS'; AxiosError.ERR_DEPRECATED = 'ERR_DEPRECATED';