[setup] console logging for niceurl tests

This commit is contained in:
Shish 2024-06-19 22:18:25 +01:00 committed by Shish
parent 069fb92f54
commit ac123317d8

View file

@ -5,25 +5,31 @@ document.addEventListener('DOMContentLoaded', () => {
if(checkbox !== null && out_span !== null) {
checkbox.disabled = true;
out_span.innerHTML = '(testing...)';
const test_url = document.body.getAttribute('data-base-href') + "/nicetest";
console.log("NiceURL testing with", test_url);
fetch(document.body.getAttribute('data-base-href') + "/nicetest").then(response => {
fetch(test_url).then(response => {
if(!response.ok) {
checkbox.disabled = true;
out_span.innerHTML = '(http error)';
console.log("NiceURL test got HTTP error:", response.status, response.statusText);
} else {
response.text().then(text => {
if(text === 'ok') {
checkbox.disabled = false;
out_span.innerHTML = '(test passed)';
console.log("NiceURL test passed");
} else {
checkbox.disabled = true;
out_span.innerHTML = '(test failed)';
console.log("NiceURL test got wrong content:", text);
}
});
}
}).catch(() => {
}).catch((e) => {
checkbox.disabled = true;
out_span.innerHTML = '(request failed)';
console.log("NiceURL test hit an exception:", e);
});
}
});