From 3c87b31f4b9dc5766429e41b4ef50bed5198a448 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 18 Aug 2022 08:44:58 -0700 Subject: [PATCH] Trypandoc: better error handling. --- trypandoc/index.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/trypandoc/index.html b/trypandoc/index.html index 26e871816..86b5ee6cc 100644 --- a/trypandoc/index.html +++ b/trypandoc/index.html @@ -212,6 +212,13 @@ function paramsFromURL() { } } +function handleErrors(response) { + if (!response.ok) { + throw Error(response.statusText); + } + return response; +} + function convert() { let text = document.getElementById("text").value; let from = document.getElementById("from").value; @@ -223,6 +230,10 @@ function convert() { if (text && text != "") { fetch("/cgi-bin/pandoc-server.cgi/version") + .then(handleErrors) + .catch(error => + document.getElementById("results").textContent = error + ) .then(response => response.text()) .then(restext => document.getElementById("version").textContent = restext