Brutal error handling...

This commit is contained in:
Nicolò P 2023-03-06 17:24:16 +01:00
parent 76a307ae8b
commit 2baef1a07e
2 changed files with 18 additions and 2 deletions

View File

@ -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...)

View File

@ -34,6 +34,7 @@
</header>
<main>
<div class="report-container">
<div id="error"></div>
<h2 class="mt-1 p-2" id="rep-tit"></h2>
<div class="columns">
<div class="column col-7">