Skip to content
Snippets Groups Projects
Verified Commit c58d590d authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: optimize rest errors

parent 10b850b7
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,7 @@ class DatasourceStatus extends CustomElement {
* @property {Object} datasource Datasource configuration
* @property {string} datasource.selector The selector of the datasource
* @property {Object} callbacks Callbacks
* @property {Function} callbacks.onError Callback function for error handling
* @property {Function} callbacks.onError Callback function for error handling <code>function(message: string, event: Event): string</code>
* @property {Object} timeouts Timeouts
* @property {number} timeouts.message Timeout for the message
* @property {Object} state State
......@@ -132,6 +132,17 @@ class DatasourceStatus extends CustomElement {
initEventHandler.call(this);
}
/**
*
* @param message
* @param timeout
* @returns {DatasourceStatus}
*/
setErrorMessage(message, timeout) {
this[errorElementSymbol].setErrorMessage(message, timeout);
return this;
}
/**
*
* @return [CSSStyleSheet]
......@@ -219,11 +230,11 @@ function initEventHandler() {
const callback = self.getOption("callbacks.onError", null);
if (callback) {
msg = callback(msg);
}
callback.call(self, msg, event);
} else {
self[errorElementSymbol].setErrorMessage(msg, timeout);
}
}
});
}
}
......
......@@ -257,6 +257,7 @@ function fetchData(init, key, callback) {
if (callback && isFunction(callback)) {
callback(obj);
}
return response;
})
.catch((e) => {
......
......@@ -32,8 +32,20 @@ class DataFetchError extends Error {
*/
constructor(message, response) {
super(message);
let body = null
if (response instanceof Response) {
body = response.text();
}
if(!(body instanceof Promise)) {
body = Promise.resolve(body);
}
this[internalSymbol] = {
response: response,
body : body
};
}
......@@ -47,10 +59,17 @@ class DataFetchError extends Error {
);
}
/**
* @return {string|Object}
*/
getBody() {
return this[internalSymbol]?.["body"];
}
/**
* @return {Response}
*/
getResponse() {
return this[internalSymbol]["response"];
return this[internalSymbol]?.["response"];
}
}
......@@ -28,7 +28,7 @@ function getInternalTranslations() {
let locale = "en";
try {
let locale = getLocaleOfDocument();
locale = getLocaleOfDocument();
} catch (error) {}
let messages = {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment