fix: enhance error handling for Axios timeout and network errors

This commit is contained in:
Nawaz Dhandala
2026-02-25 09:37:23 +00:00
parent 5a11df9d32
commit 06e784684e

View File

@@ -18,7 +18,10 @@ export function getFriendlyErrorMessage(err: unknown): string {
// Check for network / timeout errors first (no response from server)
if (!axiosError.response) {
if (axiosError.code === "ECONNABORTED" || axiosError.code === "ETIMEDOUT") {
if (
axiosError.code === "ECONNABORTED" ||
axiosError.code === "ETIMEDOUT"
) {
return "Request timed out. Please check your connection and try again.";
}
if (axiosError.code === "ERR_NETWORK") {
@@ -29,8 +32,10 @@ export function getFriendlyErrorMessage(err: unknown): string {
const { status, data } = axiosError.response;
// Extract message from response body — server sends { message: "..." }
// Also check "data" and "error" fields (matching Common/Types/API/HTTPErrorResponse.ts)
/*
* Extract message from response body — server sends { message: "..." }
* Also check "data" and "error" fields (matching Common/Types/API/HTTPErrorResponse.ts)
*/
const serverMessage: string | undefined = extractMessageFromData(data);
if (serverMessage) {