Trypandoc: better error handling.

This commit is contained in:
John MacFarlane 2022-08-18 08:44:58 -07:00
parent d01c507f25
commit 3c87b31f4b

View file

@ -212,6 +212,13 @@ function paramsFromURL() {
} }
} }
function handleErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
function convert() { function convert() {
let text = document.getElementById("text").value; let text = document.getElementById("text").value;
let from = document.getElementById("from").value; let from = document.getElementById("from").value;
@ -223,6 +230,10 @@ function convert() {
if (text && text != "") { if (text && text != "") {
fetch("/cgi-bin/pandoc-server.cgi/version") fetch("/cgi-bin/pandoc-server.cgi/version")
.then(handleErrors)
.catch(error =>
document.getElementById("results").textContent = error
)
.then(response => response.text()) .then(response => response.text())
.then(restext => .then(restext =>
document.getElementById("version").textContent = restext document.getElementById("version").textContent = restext