Closed mirontoli closed 12 years ago
Hi,
Thanks for your request and code. Agree on adding error handling, but I prefer to bubble up the error in the callback handlers instead of throwing an error.
So I changed your code a little bit:
if (js['S:Body']['S:Fault']) {
var error = js['S:Body']['S:Fault']['S:Detail']['psf:error']['psf:internalerror']['psf:text'];
callback(error);
return;
}
In the signin callback you can now check for errors:
client.signin('myname', 'mypassword', function(err,data) {
// check for errors during login, e.g. invalid credentials
if (err) {
console.log("Error found: ", err);
return;
}
// start to do authenticated requests here....
})
I hope you agree with the approach.
I agree. It is even better to bubble up error.
Before if wrong username and password were sent, it tried to get secret values. This change now checks if S:Body has S:Fault and if so pulls the text message of the failure and throws an error which is more readable.