diff options
author | stuebinm | 2021-04-07 23:02:49 +0200 |
---|---|---|
committer | stuebinm | 2021-04-07 23:02:49 +0200 |
commit | 52698489480e4803960ce29765979e687ff81ff0 (patch) | |
tree | 15e7521970ab9accc4ca2d63e362118ac65e9871 | |
parent | b38dc5c1e3b87753bf23a1d335aa2d6f7dc5ee01 (diff) |
site: better error messages
this includes deduplicating some code, and attempts at error messages
for files which could not be parsed as json but aren't actually valid
age-encrypted files (there doesn't seem to be some easy way to validate
that these files are valid age files without knowing the key).
Diffstat (limited to '')
-rw-r--r-- | site/index.html | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/site/index.html b/site/index.html index 6dc12fa..ced3af8 100644 --- a/site/index.html +++ b/site/index.html @@ -169,7 +169,7 @@ console.log(response.text()) window.location.href = "thanks.html"; } - errormsg.innerText = "POST request returned error code: " + errormsg.innerText = "POST request returned error code:\n" + response.status + ": " + response.statusText; errormsg.hidden = false; }).catch(error => { @@ -225,11 +225,22 @@ }; } + function mkReadError (msg) { + appendChildren(root, [ + mkElement("h1", "Error"), + mkElement("p", msg), + appendChildren( + mkElement("p","attempted path: "), + [mkElement("tt", surveyUrl)] + ) + ]); + } + async function main () { // initialise the web assembly parts of this await init(); const Http = new XMLHttpRequest(); - const url= surveyUrl; + const url = surveyUrl; Http.open("GET", url); Http.responseType = "arraybuffer"; Http.send(); @@ -243,31 +254,33 @@ try { survey = JSON.parse(string); } catch (e) { - console.log ("survey appears to be encrypted"); - askPassphrase(bytearray); + if (string.lastIndexOf("age-encryption.org/v1") === 0) { + console.log ("survey appears to be encrypted"); + askPassphrase(bytearray); + } else { + mkReadError ("Could not load this survey; it appears to be in a wrong or unknown format."); + } } /// if the survey was unencrypted, start it here. If it /// was encrypted, we need to wait for user action via - /// a js callback (handled in askPassphrase). + /// a js callback (handled in askPassphrase). This is + /// out here only to avoid catching errors from within mkSurvey. if (survey !== null) { mkSurvey(survey); } // couldn't load survey json, show error message } else { - appendChildren(root, [ - mkElement("h1", "Error"), - mkElement("p", "Could not load this survey; are you sure that it exists?"), - appendChildren( - mkElement("p","attempted path: "), - [mkElement("tt", surveyUrl)] - ) - ]); + mkReadError ("Could not load this survey; are you sure that it exists?"); } } } } + if (surveyUrl === "") { + mkReadError ("There's nothing here. Maybe try appending something after the url?\n\nAlternatively, check to see if you copied the whole url."); + } else { + main () + } - main () </script> </html> |