2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

docs: clarify async/await timeout error handling (#7471)

Co-authored-by: Nathanael BOT <nathanaelbot@minidenathanael.home>
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
nthbotast
2026-04-05 20:48:54 +02:00
committed by GitHub
parent 923ae8f9c5
commit 173efa3b8d
+14 -4
View File
@@ -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);
}
}
```