Added trycatch for API guessing

This commit is contained in:
Aune 2023-01-30 13:57:19 +01:00 committed by GitHub
parent 566c7626ed
commit b3213bbf5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -378,22 +378,29 @@ function get_wrapper_version(link_mode, hash) {
}
};
xhttp.withCredentials = true;
var url_current = window.location.toString();
if(window.location.includes("?")) {
url_array = window.location.split("?")
init_url = url_array[0]
} else {
init_url = window.location
}
// Try to guess API URL from current URL
Try {
var last_char = url_current.charAt(init_url.length-1);
if(last_char == "/") {
var final_url = init_url
} else {
var final_url = init_url + "/"
var window_location_str = window.location.toString();
if(window.location.includes("?")) {
url_array = window_location_str.split("?")
var init_url = url_array[0]
} else {
var init_url = window_location_str
}
var last_char = init_url.charAt(init_url.length-1);
if(last_char == "/") {
var final_url = init_url
} else {
var final_url = init_url + "/"
}
} Catch(e) {
console.log("Error occured while guessing API URL. Error: " + e);
var final_url = window.location.toString() + "/"
}
xhttp.open("post", final_url + "api/get/wrapperr-version");