There is such a "local hell of callbacks"
Made on Node.JS, help fix

function getResponse(_url) { http.get(_url, function(res) { return res; }).on('error', function(e) { log("AUTH ERROR! Reason: "+e); }); } function checkAuth(login, password) { var response = getResponse("somehost.ru", "/updater/auth.php?login="+login+"&pass="+password); if(response == "Success") { return [true, login, "user", ""]; } else { return [false, login, "user", response]; } } //часть из кода авторизации case "auth": localUserInfo = checkAuth(cmdArr[1], cmdArr[2]); if(localUserInfo[0]) { userAuthed = localUserInfo[0]; userName = localUserInfo[1]; userGroup = localUserInfo[2]; connection.send("succauth "+userName); log("User with ID: "+index+" successfully logged in! Login: "+userName); } else { log("User with ID: "+index+" failed to auth properly. Disconnecting.."); connection.send("err autherr"); connection.send("err "+localUserInfo[3]); connection.close(); } 

Exhaust from client console:

localjs.js: 34 Error: autherr
localjs.js: 34 Error: undefined
localjs.js: 40 Server closed connection ..

undefined here it is:

 localUserInfo[3] 

Closed due to the fact that off-topic participants Dmitriy Simushev , Abyx , Mstislav Pavlov , user194374, Mike Jan 31 '16 at 8:58 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Dmitriy Simushev, Abyx, Mstislav Pavlov, Community Spirit, Mike
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    A callback is when you pass another function to the function as an argument (the callback itself) that will be called when that function completes. The code in the meantime is carried further There is not a single callback in your code (or rather, there is one - an anonymous function in http.get). Because of their absence, nothing works. http.get is an asynchronous function, where return does not work the way you imagine it to be. Instead, you should just callback and pass it a response as an argument.

    Something like this should look like:

     function getResponse(_url, callback) { http.get(_url, function(res) { callback(res); }).on('error', function(e) { log("AUTH ERROR! Reason: "+e); }); } function checkAuth(login, password, callback) { getResponse("somehost.ru/updater/auth.php?login="+login+"&pass="+password,function(response){ if(response == "Success") { callback([true, login, "user", ""]); } else { callback([false, login, "user", response]); } }); } //часть из кода авторизации case "auth": checkAuth(cmdArr[1], cmdArr[2],function(localUserInfo){ if(localUserInfo[0]) { ......... } else { ......... } }); 
    • I love you, Darth, thanks for the help! - AGrief