exports.addAccount = async function(username, password){
var request = require('request');
var data = '{"login": "' + username + '","password":"' + password + '" }';
var json_obj = JSON.parse(data);
error = request.post({
headers: {'content-type': 'application/json'},
url: 'https://example.su/engine/auth.php',
form: json_obj
}, async function* (error, response, body){
try {
response = JSON.parse(body);
if(response.error){
return 'error' + response.error;
}else{
try {
if(response.id){
const ret = ConfigManager.addAuthAccount(response.id, response.hash,
response.email, response.username)
if(ConfigManager.getClientToken() == null){
ConfigManager.setClientToken(response.hash);
}
ConfigManager.save();
return ret;
}
} catch (e) {
return "error";
}
}
} catch (e) {
return "error";
}
});
if(error.includes('error')){
//*****************
}
}
How to redirect return from a nested function? or how to write the response body to the variable 'error'? How can this be implemented? redo the authorization mechanism in the program?