mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 12:16:21 +03:00
Updated error handling in authenticator
This commit is contained in:
parent
61f8af7a20
commit
18ac2852e2
1 changed files with 29 additions and 26 deletions
|
@ -3,7 +3,7 @@ const uuid = require('uuid/v1');
|
||||||
const api_url = "https://authserver.mojang.com";
|
const api_url = "https://authserver.mojang.com";
|
||||||
|
|
||||||
module.exports.getAuth = function (username, password) {
|
module.exports.getAuth = function (username, password) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!password) {
|
if (!password) {
|
||||||
const user = {
|
const user = {
|
||||||
access_token: uuid(),
|
access_token: uuid(),
|
||||||
|
@ -32,9 +32,9 @@ module.exports.getAuth = function (username, password) {
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function (error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
if(!body.selectedProfile) {
|
if (!body || !body.selectedProfile) {
|
||||||
throw new Error("Validation error: " + response.statusMessage);
|
return reject("Validation error: " + response.statusMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const userProfile = {
|
const userProfile = {
|
||||||
|
@ -52,7 +52,7 @@ module.exports.getAuth = function (username, password) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.validate = function (access_token, client_token) {
|
module.exports.validate = function (access_token, client_token) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/validate",
|
url: api_url + "/validate",
|
||||||
json: {
|
json: {
|
||||||
|
@ -62,15 +62,16 @@ module.exports.validate = function (access_token, client_token) {
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, async function (error, response, body) {
|
request.post(requestObject, async function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
|
|
||||||
if(!body) resolve(true); else resolve(false);
|
if (!body) resolve(true);
|
||||||
|
else reject(body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile) {
|
module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/refresh",
|
url: api_url + "/refresh",
|
||||||
json: {
|
json: {
|
||||||
|
@ -82,9 +83,9 @@ module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function (error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
if(!body.selectedProfile) {
|
if (!body || !body.selectedProfile) {
|
||||||
throw new Error("Validation error: " + response.statusMessage);
|
return reject("Validation error: " + response.statusMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const userProfile = {
|
const userProfile = {
|
||||||
|
@ -101,7 +102,7 @@ module.exports.refreshAuth = function (accessToken, clientToken, selectedProfile
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.invalidate = function (accessToken, clientToken) {
|
module.exports.invalidate = function (accessToken, clientToken) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/invalidate",
|
url: api_url + "/invalidate",
|
||||||
json: {
|
json: {
|
||||||
|
@ -111,15 +112,16 @@ module.exports.invalidate = function(accessToken, clientToken) {
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function (error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
|
|
||||||
if(!body) resolve(true); else resolve(false);
|
if (!body) resolve(true);
|
||||||
|
else reject(body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.signOut = function (username, password) {
|
module.exports.signOut = function (username, password) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
const requestObject = {
|
const requestObject = {
|
||||||
url: api_url + "/signout",
|
url: api_url + "/signout",
|
||||||
json: {
|
json: {
|
||||||
|
@ -129,9 +131,10 @@ module.exports.signOut = function(username, password) {
|
||||||
};
|
};
|
||||||
|
|
||||||
request.post(requestObject, function (error, response, body) {
|
request.post(requestObject, function (error, response, body) {
|
||||||
if (error) resolve(error);
|
if (error) return reject(error);
|
||||||
|
|
||||||
if(!body) resolve(true); else resolve(false);
|
if (!body) resolve(true);
|
||||||
|
else reject(body);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue