introduced new exception classes for structured error reporting

This commit is contained in:
zadam
2022-12-09 16:04:13 +01:00
parent eaf195e0c8
commit 342ae6e5e2
27 changed files with 123 additions and 64 deletions

View File

@@ -1,4 +1,5 @@
import utils from './utils.js';
import ValidationError from "./validation_error.js";
const REQUEST_LOGGING_ENABLED = false;
@@ -102,10 +103,15 @@ async function call(method, url, data, headers = {}) {
return resp.body;
}
async function reportError(method, url, status, error) {
const message = "Error when calling " + method + " " + url + ": " + status + " - " + error;
async function reportError(method, url, status, response) {
const toastService = (await import("./toast.js")).default;
if ([400, 404].includes(status) && response && typeof response === 'object') {
toastService.showError(response.message);
throw new ValidationError(response);
}
const message = "Error when calling " + method + " " + url + ": " + status + " - " + responseText;
toastService.showError(message);
toastService.throwError(message);
}