diff --git a/packages/common/i18n/de/translation.json b/packages/common/i18n/de/translation.json index 3664695d8d95aa3a19dd281f217e681b00b542ea..879cba7624f22fceb5bbb933ecd06249695a792c 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 57a8fb3ea3426cf5cb98b5e0032453a6009b19eb..e9cbcac4405a9b51666b85a5c474aba1eefec9c2 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 7cf99b09fc587218b0b257a1f6c3525944a4b1db..3292e80bbb3f3b54add2e68a89f093cd1f2a5f68 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]; }