Skip to content

Commit

Permalink
Try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
aunefyren committed Nov 23, 2023
1 parent 8229e7a commit fb1f91c
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions web/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,42 +76,37 @@ function get_login(cookie) {
if (this.readyState == 4) {

var result;
if(result = JSON.parse(this.responseText)) {
// If the error is to verify, allow loading page anyways
if(result.error === "You must verify your account.") {

// If not front-page, redirect
if(window.location.pathname !== "/verify") {
location.href = '/verify';
return;
}

// Load page
load_page(this.responseText)

} else if (result.error) {

error(result.error)
showLoggedInMenu();
try {
result = JSON.parse(this.responseText)
} catch(e) {
console.log("Failed to parse JSON. Error: " + e)
load_page(false);
}

// If the error is to verify, allow loading page anyways
if(result.error === "You must verify your account.") {
// If not front-page, redirect
if(window.location.pathname !== "/verify") {
location.href = '/verify';
return;

} else {

// If new token, save it
if(result.token != null && result.token != "") {
// store jwt to cookie
console.log("Refreshed login token.")
set_cookie("poenskelisten", result.token, 7);
}

// Load page
load_page(this.responseText)

}
// Load page
load_page(this.responseText)
} else if (result.error) {
error(result.error)
showLoggedInMenu();
return;
} else {
load_page(false);
}
// If new token, save it
if(result.token != null && result.token != "") {
// store jwt to cookie
console.log("Refreshed login token.")
set_cookie("poenskelisten", result.token, 7);
}

// Load page
load_page(this.responseText)
}
}
};
xhttp.withCredentials = true;
Expand Down

0 comments on commit fb1f91c

Please sign in to comment.