ocilo / skype-http

Unofficial Skype API for Node.js via HTTP
https://ocilo.github.io/skype-http
MIT License
51 stars 24 forks source link

invalid login error is cryptic #22

Closed mitchcapper closed 7 years ago

mitchcapper commented 7 years ago

when you have an invalid login the error (even with a full BT) is a bit cryptic:

Unhandled rejection due to: [object Promise]={}: Error: Expected value of Skype token to be a string
    at Object.<anonymous> (C:\temp\skytest\node_modules\skype-http\dist\lib-es2015\lib\providers\lib\providers\microsoft-account.ts:77:11)
    at Generator.next (<anonymous>)
    at fulfilled (C:\temp\skytest\node_modules\skype-http\dist\lib-es2015\lib\providers\microsoft-account.js:4:58)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Do you want to try/catch on this to make it more apartent or better inspect the returned data to determine if it is a login failure? I can submit a PR if you want to specify direction.

demurgos commented 7 years ago

This error was caused by this line. The Skype token was not found here while scrapping the last page of the login procedure. I agree that the error should provided more context: the HTML response and explain that the Skype token was not found, this can be caused by a change in the Microsoft login procedure (or invalid credentials ?). This kind of errors is exactly what I'd like to better support.

What kind of account are you using ? Email ? Skype username ? Phone number ? Could you check with the example in the repo ? (npm install && npm start) Could you log the HTML response ?

mitchcapper commented 7 years ago

Sorry to clarify I am able to login just fine with the correct creds (skype account not MSA). I made a typo the first time however and got the above error and quickly determined the issue. To another consumer of the lib may not be as obvious. Happy to write some error handling to make it easy for others just let me know best way to go.

demurgos commented 7 years ago

You definitely succeeded in restoring my motivation to work on this library 😄

My idea would be to define error interfaces with a unique name. Switching on the name should allow to resolve the type of the error. Each error type should be associated with some data to process it automatically and an error message to help the developer. Additionally, it should be possible to combine multiple kinds of errors (causes) into a more abstract error to ease the error handling.

About this issue, I think that there should be a LoginError, and some possible causes could be WrongCredentialsError, NetworkError, UnexpectedResponseError, etc. I'll send a PR for the LoginError, it will serve as an example because I'd like to have this sort of errors for the whole API.

mitchcapper commented 7 years ago

Sounds good. My goal of the API is to use in a very stable long term connection to be able to finally ditch the skype client for most interaction. As I find other errors thrown happy to follow the style to make them easier to handle and less cryptic to users.

demurgos commented 7 years ago

@mitchcapper This issue should be fixed by #26.

Here are some examples of errors:

Username? invaliduser
Password? invalidpassword
MicrosoftAccountLogin: Unable to login with MicrosoftAccount.
  caused by WrongCredentials: Wrong credentials for the user "invaliduser"
Username? invaliduser
Password? invalidpassword
MicrosoftAccountLogin: Unable to login with MicrosoftAccount.
  caused by WrongCredentialsLimit: You've tried to sign in too many times with an incorrect account or password