From 2b28434712004d229869c3f56e1e9fbcc7effe6f Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Tue, 18 Feb 2020 14:32:59 +0100 Subject: [PATCH 1/2] Rethrow unhandled error from API hooks. --- src/api/hooks.js | 9 ++++++++- src/api/utils.js | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api/hooks.js b/src/api/hooks.js index 05503ae..1b245af 100644 --- a/src/api/hooks.js +++ b/src/api/hooks.js @@ -53,10 +53,11 @@ function createAPIHook(method) { payload: result.data, }); } catch (error) { + const errorPayload = getErrorPayload(error); dispatch({ type: API_ACTIONS.FAILURE, status: error.response && error.response.status, - payload: getErrorPayload(error), + payload: errorPayload, }); } }, [urlRoot, contentType]); @@ -80,6 +81,12 @@ function APIReducer(state, action) { if (action.status === 403) { window.location.assign(ForisURLs.login); } + + // Not an API error - should be rethrown. + if (action.payload && action.payload.stack && action.payload.message) { + throw (action.payload); + } + return { state: API_STATE.ERROR, data: action.payload, diff --git a/src/api/utils.js b/src/api/utils.js index 9da04a0..c8e340c 100644 --- a/src/api/utils.js +++ b/src/api/utils.js @@ -65,9 +65,8 @@ export function getErrorPayload(error) { if (error.request) { return _("No response received."); } - /* eslint no-console: "off" */ - console.error(error); - return _("An unknown error occurred. Check the console for more info."); + // Return original error because it's not directly related to API request/response. + return error; } export function getJSONErrorMessage(error) { From 0665869c3077b3f14ffe75b4dbc55be1835f4bc3 Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Wed, 19 Feb 2020 10:34:47 +0100 Subject: [PATCH 2/2] Changed version to 4.0.0. --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index f2ccb66..86e6b91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "3.4.0", + "version": "4.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 531f7df..59b19b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "3.4.0", + "version": "4.0.0", "description": "Set of components and utils for Foris and its plugins.", "author": "CZ.NIC, z.s.p.o.", "repository": {