From fa00222f58c835911924f614a7f38314f7c36ea0 Mon Sep 17 00:00:00 2001 From: Johan van Soest Date: Mon, 27 May 2024 15:16:59 +0200 Subject: [PATCH] added messages when backend is not available or response from server is not ok (!=200) --- src/templates/cee.html | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/templates/cee.html b/src/templates/cee.html index 40468d0..aef800b 100644 --- a/src/templates/cee.html +++ b/src/templates/cee.html @@ -83,19 +83,31 @@ const meta = cee.currentMetadata; const info = cee.templateInfo; const xhr = new XMLHttpRequest(); + xhr.onerror = function(e){ + alert("An error occured while saving the form. Server response not received."); + }; payload = { 'metadata': meta, 'info': info } + if (!cee.templateInfo) { xhr.open("POST", window.location.origin + "/api/cedar/store"); } else { xhr.open("PUT", window.location.origin + "/api/cedar/store"); } + xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.onload = () => { + if (xhr.status == 200) { + window.location.href = window.location.origin + } else { + window.alert("An error occured while saving the form. Please try again later.") + } + }; xhr.send(JSON.stringify(payload, null, 2)); - console.log("Attempted to store data"); }