Skip to content

Commit

Permalink
improved error toast and showing errors from Ditto
Browse files Browse the repository at this point in the history
* display error toast also for message responses with "failed" response code
* but still display the response as well in the messages response ace editor
* still show JSON errors which are not formatted as "ditto error" (containing at least status and message)

Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
  • Loading branch information
thjaeckle committed Nov 24, 2023
1 parent d66fa72 commit 3ce5b55
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ui/modules/api.ts
Expand Up @@ -307,6 +307,14 @@ export function setAuthHeader(forDevOps) {
}
}

function showDittoError(dittoErr, response) {
if (dittoErr.status && dittoErr.message) {
Utils.showError(dittoErr.description + `\n(${dittoErr.error})`, dittoErr.message, dittoErr.status);
} else {
Utils.showError(JSON.stringify(dittoErr), 'Error', response.status);
}
}

/**
* Calls the Ditto api
* @param {String} method 'POST', 'GET', 'DELETE', etc.
Expand Down Expand Up @@ -346,12 +354,15 @@ export async function callDittoREST(method,
if (returnHeaders) {
return response;
} else {
return response.json();
return response.json().then((dittoErr) => {
showDittoError(dittoErr, response);
return dittoErr;
});
}
} else {
response.json()
.then((dittoErr) => {
Utils.showError(dittoErr.description + `\n(${dittoErr.error})`, dittoErr.message, dittoErr.status);
showDittoError(dittoErr, response);
})
.catch((err) => {
Utils.showError('No error details from Ditto', response.statusText, response.status);
Expand Down Expand Up @@ -423,7 +434,7 @@ export async function callConnectionsAPI(operation, successCallback, connectionI
if (!response.ok) {
response.json()
.then((dittoErr) => {
Utils.showError(dittoErr.description, dittoErr.message, dittoErr.status);
showDittoError(dittoErr, response);
})
.catch((err) => {
Utils.showError('No error details from Ditto', response.statusText, response.status);
Expand All @@ -436,7 +447,7 @@ export async function callConnectionsAPI(operation, successCallback, connectionI
.then((data) => {
if (data && data['?'] && data['?']['?'].status >= 400) {
const dittoErr = data['?']['?'].payload;
Utils.showError(dittoErr.description, dittoErr.message, dittoErr.status);
showDittoError(dittoErr, response);
} else {
if (params.unwrapJsonPath) {
params.unwrapJsonPath.split('.').forEach(function(node) {
Expand Down

0 comments on commit 3ce5b55

Please sign in to comment.