Refactor the xhr so other requests can reuse the code
This commit is contained in:
parent
21a29a09eb
commit
e117dc5540
|
@ -7,6 +7,19 @@ init().then(() => {
|
|||
});
|
||||
|
||||
function request_open_invite() {
|
||||
return new Promise((fulfill, reject) => {
|
||||
loxServerRequest("").then((response) => {
|
||||
console.log("Got invitation token: " + response.invite);
|
||||
fulfill(response.invite);
|
||||
return;
|
||||
}).catch(() => {
|
||||
console.log("Error requesting open invite from Lox server");
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loxServerRequest(data) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
|
@ -20,8 +33,7 @@ function request_open_invite() {
|
|||
return;
|
||||
}
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
console.log("Got invitation token: "+response.invite);
|
||||
fulfill(response.invite);
|
||||
fulfill(response);
|
||||
return;
|
||||
};
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue