1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Improve some notifications

This commit is contained in:
Sonja Happ 2021-01-07 16:27:27 +01:00
parent e49456490c
commit 631bb7d57c
2 changed files with 7 additions and 7 deletions

View file

@ -23,14 +23,14 @@ import NotificationsFactory from "../data-managers/notifications-factory";
// Check if the error was due to network failure, timeouts, etc.
// Can be used for the rest of requests
function isNetworkError(err) {
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;
let notification = err.timeout? NotificationsFactory.REQUEST_TIMEOUT : NotificationsFactory.SERVER_NOT_REACHABLE;
let notification = err.timeout? NotificationsFactory.REQUEST_TIMEOUT : NotificationsFactory.SERVER_NOT_REACHABLE(url);
NotificationsDataManager.addNotification(notification);
}
return result;
@ -49,7 +49,7 @@ class RestAPI {
req.end(function (error, res) {
if (res == null || res.status !== 200) {
if (req.url !== prevURL) error.handled = isNetworkError(error);
if (req.url !== prevURL) error.handled = isNetworkError(error, url);
prevURL = req.url;
reject(error);
} else {

View file

@ -26,18 +26,18 @@ class NotificationsFactory {
};
}
static get SERVER_NOT_REACHABLE() {
static SERVER_NOT_REACHABLE(url) {
return {
title: 'Server not reachable',
message: 'The server could not be reached. Please try again later.',
message: 'The url ' + url +' could not be reached. Please try again later.',
level: 'error'
};
}
static get REQUEST_TIMEOUT() {
static REQUEST_TIMEOUT(url) {
return {
title: 'Request timeout',
message: 'Request timed out. Please try again later.',
message: 'Request to ' + url + ' timed out. Please try again later.',
level: 'error'
};
}