lstak / node-sharepoint

Connecting Node and SharePoint
http://allthatjs.com/2012/03/29/node-js-meet-sharepoint/
104 stars 41 forks source link

Handling of authentification failure #1

Closed mirontoli closed 12 years ago

mirontoli commented 12 years ago

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.

lstak commented 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.

mirontoli commented 12 years ago

I agree. It is even better to bubble up error.