From f5825f2fa153f572ff05e039fc627c44fab1ac53 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Fri, 29 Jan 2021 09:40:23 +0100 Subject: [PATCH] add notification for internal server error --- src/common/api/rest-api.js | 9 ++++++--- src/common/data-managers/notifications-factory.js | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/common/api/rest-api.js b/src/common/api/rest-api.js index b33c36f..c35c0d3 100644 --- a/src/common/api/rest-api.js +++ b/src/common/api/rest-api.js @@ -26,10 +26,13 @@ import NotificationsFactory from "../data-managers/notifications-factory"; function isNetworkError(err, url) { let result = false; - // If not status nor response fields, it is a network error. TODO: Handle timeouts - if (err.status == null || err.status === 500 || err.response == null) { - result = true; + if (err.status === 500 && err.response != null){ + let notification = NotificationsFactory.INTERNAL_SERVER_ERROR(err.response) + NotificationsDataManager.addNotification(notification); + } else if (err.status == null || err.status === 500 || err.response == null) { + // If not status nor response fields, it is a network error. TODO: Handle timeouts + result = true; let notification = err.timeout? NotificationsFactory.REQUEST_TIMEOUT : NotificationsFactory.SERVER_NOT_REACHABLE(url); NotificationsDataManager.addNotification(notification); } diff --git a/src/common/data-managers/notifications-factory.js b/src/common/data-managers/notifications-factory.js index 7b4867b..ece1e8b 100644 --- a/src/common/data-managers/notifications-factory.js +++ b/src/common/data-managers/notifications-factory.js @@ -42,6 +42,14 @@ class NotificationsFactory { }; } + static INTERNAL_SERVER_ERROR(response) { + return { + title: 'Internal server error', + message: response.message, + level: 'error' + }; + } + static ADD_ERROR(message) { return { title: "Add Error",