Skip to content
Snippets Groups Projects
Commit 2126fd02 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Add jsonld server connection and other error notifications

parent 04e8cfe3
No related branches found
No related tags found
No related merge requests found
...@@ -2,5 +2,10 @@ ...@@ -2,5 +2,10 @@
"error": { "error": {
"summary": "Ein Fehler ist aufgetreten", "summary": "Ein Fehler ist aufgetreten",
"connection-to-server-refused": "Verbindungs zum Server verweigert!" "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!"
} }
} }
...@@ -2,5 +2,10 @@ ...@@ -2,5 +2,10 @@
"error": { "error": {
"summary": "An error occurred", "summary": "An error occurred",
"connection-to-server-refused": "Connection to server refused!" "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!"
} }
} }
"use strict"; "use strict";
import {send as notify} from './notification';
import * as utils from "./utils"; import * as utils from "./utils";
import {i18n} from "./i18n";
let instances = {}; let instances = {};
let successFunctions = {}; let successFunctions = {};
...@@ -106,25 +108,41 @@ export default class JSONLD { ...@@ -106,25 +108,41 @@ export default class JSONLD {
for (const fnc of successFunctions[apiUrl]) if (typeof fnc == 'function') fnc(instance); for (const fnc of successFunctions[apiUrl]) if (typeof fnc == 'function') fnc(instance);
successFunctions[apiUrl] = []; successFunctions[apiUrl] = [];
} else { } else {
for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); JSONLD.executeFailureFunctions(apiUrl, i18n.t('jsonld.api-documentation-server', { apiUrl: apiDocUrl }));
failureFunctions[apiUrl] = [];
} }
}; };
docXhr.send(); docXhr.send();
} else { } else {
for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); JSONLD.executeFailureFunctions(apiUrl, i18n.t('jsonld.error-hydra-documentation-url-not-set', { apiUrl: apiUrl }));
failureFunctions[apiUrl] = [];
} }
} else { } else {
for (const fnc of failureFunctions[apiUrl]) if (typeof fnc == 'function') fnc(); JSONLD.executeFailureFunctions(apiUrl, i18n.t('jsonld.error-api-server', { apiUrl: apiUrl }));
failureFunctions[apiUrl] = [];
} }
}; };
xhr.send(); 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) { static getInstance(apiUrl) {
return instances[apiUrl]; return instances[apiUrl];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment