fix login page error handling
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
fcdfe020c6
commit
aacc264314
@ -1,4 +1,4 @@
|
|||||||
import {requestTicket, setTicket, ResponseError, NetworkError, goToPage, deleteAllCookies, requestPVE} from "./utils.js";
|
import {requestTicket, setTicket, NetworkError, goToPage, deleteAllCookies, requestPVE} from "./utils.js";
|
||||||
import {alert} from "./dialog.js";
|
import {alert} from "./dialog.js";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
@ -18,27 +18,26 @@ async function init (){
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let form = document.querySelector("form");
|
let form = document.querySelector("form");
|
||||||
let formData = new FormData(form);
|
let formData = new FormData(form);
|
||||||
try {
|
|
||||||
formSubmitButton.innerText = "Authenticating...";
|
formSubmitButton.innerText = "Authenticating...";
|
||||||
let ticket = await requestTicket(formData.get("username"), formData.get("password"), formData.get("realm"));
|
let ticket = await requestTicket(formData.get("username"), formData.get("password"), formData.get("realm"));
|
||||||
|
if (ticket.status === 200) {
|
||||||
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken, formData.get("username"));
|
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken, formData.get("username"));
|
||||||
formSubmitButton.innerText = "LOGIN";
|
formSubmitButton.innerText = "LOGIN";
|
||||||
goToPage("index.html");
|
goToPage("index.html");
|
||||||
}
|
}
|
||||||
catch (error) {
|
else if (ticket.status === 401) {
|
||||||
if(error instanceof ResponseError) { // response error is usually 401 auth failed
|
|
||||||
alert("Authenticaton failed.");
|
alert("Authenticaton failed.");
|
||||||
formSubmitButton.innerText = "LOGIN";
|
formSubmitButton.innerText = "LOGIN";
|
||||||
}
|
}
|
||||||
else if (error instanceof NetworkError) {
|
else if (ticket.status === 408) {
|
||||||
alert("Network error.");
|
alert("Network error.");
|
||||||
formSubmitButton.innerText = "LOGIN";
|
formSubmitButton.innerText = "LOGIN";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alert("An error.");
|
alert("An error occured.");
|
||||||
formSubmitButton.innerText = "LOGIN";
|
formSubmitButton.innerText = "LOGIN";
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user