From 2baef1a07e14ff9da093d565bc532846f8e0a735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P?= Date: Mon, 6 Mar 2023 17:24:16 +0100 Subject: [PATCH] Brutal error handling... --- js/ds.js | 19 +++++++++++++++++-- report/index.html | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/ds.js b/js/ds.js index 6547cc0..e485d00 100644 --- a/js/ds.js +++ b/js/ds.js @@ -89,11 +89,13 @@ DataSpace.createObjectShape = function(resource) { */ DataSpace.fetchReport = async function(uuid, format='json') { - // TODO Errors!! const jsonRep = await fetch(`${this.BASE_URL}${this.RES_ENDPOINT}${uuid}?format=${format}&indent=2`) .then(res => res.json()) - .catch(); + .catch(excep => { + _createError(excep, 'error') + document.querySelector('.modal').classList.remove('active'); + }); return jsonRep; } @@ -161,6 +163,19 @@ DataSpace.getImagesSrc = function(resource) { return fileNames; } +function _createError(message, htmlId) +{ + const error = document.createElement('div'); + const clear = document.createElement('button'); + error.className = 'toast toast-error'; + clear.className = 'btn btn-clear float-right'; + + error.appendChild(clear); + error.textContent = message; + + document.querySelector(`#${htmlId}`).appendChild(error); +} + export default DataSpace; /** * Fetch file blob (CORS...) diff --git a/report/index.html b/report/index.html index bbe0e34..54e9067 100644 --- a/report/index.html +++ b/report/index.html @@ -34,6 +34,7 @@
+