From 173efa3b8dd3f331c397519394ad6188d6945d2e Mon Sep 17 00:00:00 2001 From: nthbotast Date: Sun, 5 Apr 2026 20:48:54 +0200 Subject: [PATCH] docs: clarify async/await timeout error handling (#7471) Co-authored-by: Nathanael BOT Co-authored-by: Jay --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e49ab026..a8d2a1b8 100644 --- a/README.md +++ b/README.md @@ -1011,15 +1011,25 @@ async function fetchWithTimeout() { try { const response = await axios.get("https://example.com/data", { timeout: 5000, // 5 seconds + transitional: { + // set to true if you prefer ETIMEDOUT over ECONNABORTED + clarifyTimeoutError: false, + }, }); console.log("Response:", response.data); } catch (error) { - if (axios.isAxiosError(error) && error.code === "ECONNABORTED") { - console.error("❌ Request timed out!"); - } else { - console.error("❌ Error:", error.message); + if (axios.isAxiosError(error)) { + if (error.code === "ECONNABORTED" || error.code === "ETIMEDOUT") { + console.error("Request timed out. Please try again."); + return; + } + + console.error("Axios error:", error.message); + return; } + + console.error("Unexpected error:", error); } } ```