From 2126fd028dc5d141eff9bc99c727e2e9b92b6ad9 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio.bekerle@tugraz.at> Date: Thu, 12 Sep 2019 15:13:29 +0200 Subject: [PATCH] Add jsonld server connection and other error notifications --- packages/common/i18n/de/translation.json | 5 ++++ packages/common/i18n/en/translation.json | 5 ++++ packages/common/jsonld.js | 30 +++++++++++++++++++----- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/common/i18n/de/translation.json b/packages/common/i18n/de/translation.json index 3664695d..879cba76 100644 --- a/packages/common/i18n/de/translation.json +++ b/packages/common/i18n/de/translation.json @@ -2,5 +2,10 @@ "error": { "summary": "Ein Fehler ist aufgetreten", "connection-to-server-refused": "Verbindungs zum Server verweigert!" + }, + "jsonld": { + "error-api-server": "Verbindung zum API Server {{apiUrl}} fehlgeschlagen!", + "error-hydra-documentation-url-not-set": "Hydra apiDocumentation URL wurden für server {{apiUrl}} nicht gesetzt!", + "api-documentation-server": "Verbindung zum apiDocumentation API Server {{apiDocUrl}} fehlgeschlagen!" } } diff --git a/packages/common/i18n/en/translation.json b/packages/common/i18n/en/translation.json index 57a8fb3e..e9cbcac4 100644 --- a/packages/common/i18n/en/translation.json +++ b/packages/common/i18n/en/translation.json @@ -2,5 +2,10 @@ "error": { "summary": "An error occurred", "connection-to-server-refused": "Connection to server refused!" + }, + "jsonld": { + "error-api-server": "Connection to api server {{apiUrl}} failed!", + "error-hydra-documentation-url-not-set": "Hydra apiDocumentation url was not set for server {{apiUrl}}!", + "api-documentation-server": "Connection to apiDocumentation server {{apiDocUrl}} failed!" } } diff --git a/packages/common/jsonld.js b/packages/common/jsonld.js index 7cf99b09..3292e80b 100644 --- a/packages/common/jsonld.js +++ b/packages/common/jsonld.js @@ -1,6 +1,8 @@ "use strict"; +import {send as notify} from './notification'; import * as utils from "./utils"; +import {i18n} from "./i18n"; let instances = {}; let successFunctions = {}; @@ -106,25 +108,41 @@ export default class JSONLD { for (const fnc of successFunctions[apiUrl]) if (typeof fnc == 'function') fnc(instance); successFunctions[apiUrl] = []; } else { - for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); - failureFunctions[apiUrl] = []; + JSONLD.executeFailureFunctions(apiUrl, i18n.t('jsonld.api-documentation-server', { apiUrl: apiDocUrl })); } }; docXhr.send(); } else { - for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); - failureFunctions[apiUrl] = []; + JSONLD.executeFailureFunctions(apiUrl, i18n.t('jsonld.error-hydra-documentation-url-not-set', { apiUrl: apiUrl })); } } else { - for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); - failureFunctions[apiUrl] = []; + JSONLD.executeFailureFunctions(apiUrl, i18n.t('jsonld.error-api-server', { apiUrl: apiUrl })); } }; xhr.send(); } + /** + * Execute failure functions and send general notification + * + * @param apiUrl + * @param message + */ + static executeFailureFunctions(apiUrl, message = "") { + for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); + failureFunctions[apiUrl] = []; + + if (message !== "") { + notify({ + "summary": i18n.t('error.summary'), + "body": message, + "type": "danger", + }); + } + } + static getInstance(apiUrl) { return instances[apiUrl]; } -- GitLab