1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-06-28 20:03:59 +00:00

Add timout handling.

This commit is contained in:
Bogdan Bodnar 2019-11-12 15:26:54 +01:00
parent 0f5b35a3ba
commit b831d664a9
No known key found for this signature in database
GPG Key ID: 49E4169AD3CA42B0
2 changed files with 6 additions and 3 deletions

View File

@ -42,7 +42,7 @@ function createAPIHook(method) {
dispatch({ dispatch({
type: API_ACTIONS.FAILURE, type: API_ACTIONS.FAILURE,
payload: getErrorMessage(error), payload: getErrorMessage(error),
status: error.response.status, status: error.response && error.response.status,
}); });
} }
}, [url, contentType]); }, [url, contentType]);

View File

@ -53,9 +53,12 @@ function getCookie(name) {
} }
export function getErrorMessage(error) { export function getErrorMessage(error) {
let payload = "An unknown error occurred"; let payload = _("An unknown error occurred.");
if (error.response.headers["content-type"] === "application/json") { if (error.response && error.response.headers["content-type"] === "application/json") {
payload = error.response.data; payload = error.response.data;
} }
if (error.code === "ECONNABORTED") {
payload = _("Timeout error occurred.");
}
return payload; return payload;
} }