diff --git a/the_works/templates/views/werk.html b/the_works/templates/views/werk.html index f2e6bbf..630207b 100644 --- a/the_works/templates/views/werk.html +++ b/the_works/templates/views/werk.html @@ -27,7 +27,14 @@ let id = this.dataset.id; let url = `${SCRIPT_ROOT}/werk/read/${id}`; fetch(url) - .then(response => response.json()) + // throw error if network error occurred, get JSON data otherwise + .then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error ("There was an error while fetching data for the text with ID " + id); + }) + // populate modal with response data and raise modal .then( function (response) { // set modal heading @@ -44,7 +51,7 @@ document.getElementById("werkmodal").showModal(); } ) - .catch(console.log("all is lost :-(")); + .catch((error) => console.log(error)); } window.onload = function () { @@ -107,7 +114,7 @@