From b831d664a93059f5c3915605cc742e559e61f889 Mon Sep 17 00:00:00 2001 From: Bogdan Bodnar Date: Tue, 12 Nov 2019 15:26:54 +0100 Subject: [PATCH] Add timout handling. --- src/api/hooks.js | 2 +- src/api/utils.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/hooks.js b/src/api/hooks.js index a30bd8d..aa19988 100644 --- a/src/api/hooks.js +++ b/src/api/hooks.js @@ -42,7 +42,7 @@ function createAPIHook(method) { dispatch({ type: API_ACTIONS.FAILURE, payload: getErrorMessage(error), - status: error.response.status, + status: error.response && error.response.status, }); } }, [url, contentType]); diff --git a/src/api/utils.js b/src/api/utils.js index 18a76e3..d727c80 100644 --- a/src/api/utils.js +++ b/src/api/utils.js @@ -53,9 +53,12 @@ function getCookie(name) { } export function getErrorMessage(error) { - let payload = "An unknown error occurred"; - if (error.response.headers["content-type"] === "application/json") { + let payload = _("An unknown error occurred."); + if (error.response && error.response.headers["content-type"] === "application/json") { payload = error.response.data; } + if (error.code === "ECONNABORTED") { + payload = _("Timeout error occurred."); + } return payload; }