Skip to content

Commit

Permalink
added messages when backend is not available or response from server …
Browse files Browse the repository at this point in the history
…is not ok (!=200)
  • Loading branch information
jvsoest committed May 27, 2024
1 parent 9a3aa9b commit fa00222
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/templates/cee.html
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
</script>
</head>
Expand Down

0 comments on commit fa00222

Please sign in to comment.