summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--site/index.html41
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>