Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Catch Authentication Errors #80

Closed
brycelund opened this issue Sep 14, 2018 · 3 comments
Closed

Catch Authentication Errors #80

brycelund opened this issue Sep 14, 2018 · 3 comments

Comments

@brycelund
Copy link

brycelund commented Sep 14, 2018

What is the correct way to catch errors on login? If someone enters incorrect credentials, the module throws an error, but I'm unable to catch them and the script crashes. Has anyone successfully done this?

Code being executed:

      try{
         var Robinhood = require('robinhood')({
              username : username,
              password : password
          }, function(result){
                console.log("Login callback", result);
            });
       } catch (e) {
            console.log("ERROR:",e);
       }
/opt/bitnami/apache2/htdocs/node_modules/robinhood/src/robinhood.js:141
          throw new Error(
          ^

Error: token not found {"statusCode":400,"body":{"detail":"Unable to log in with provided credentials."},"headers":{"date":"Fri, 14 Sep 2018 00:55:06 GMT","content-type":"application/json","content-length":"56","connection":"keep-alive","server":"nginx","content-language":"en-us","x-robinhood-api-version":"1.244.14","vary":"Accept-Language, Cookie","allow":"POST, OPTIONS"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"api.robinhood.com","port":443,"hostname":"api.robinhood.com","hash":null,"search":null,"query":null,"pathname":"/oauth2/token/","path":"/oauth2/token/","href":"https://api.robinhood.com/oauth2/token/"},"method":"POST","headers":{"Accept":"*/*","Accept-Encoding":"gzip, deflate","Accept-Language":"en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5","Content-Type":"application/x-www-form-urlencoded; charset=utf-8","Connection":"keep-alive","X-Robinhood-API-Version":"1.152.0","User-Agent":"Robinhood/5.32.0 (com.robinhood.release.Robinhood; build:3814; iOS 10.3.3)","content-length":134}}}
    at Request._callback (/opt/bitnami/apache2/htdocs/node_modules/robinhood/src/robinhood.js:141:17)
    at Request.self.callback (/opt/bitnami/apache2/htdocs/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/opt/bitnami/apache2/htdocs/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/opt/bitnami/apache2/htdocs/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
@evanshortiss
Copy link
Contributor

@brycelund I was wondering this also. The module design doesn't allow them to be captured since it throws in an asynchronous manner.

A simple fix would be to update:

  1. The throw here
  2. Another throw here
  3. And here

Replace the throws with:

callback(new AuthenticationError('token missing from response body'))

and

// wrap the network/request errors with VError
callback(new VError(err, 'failed to fetch account')) // line 164/155
callback(new VError(err, 'failed to perform login call')) // line 137

Could be an easy enough PR, but also a breaking change since the login callback would now become callback(error, data) instead of the current callback(data). This would be a good thing since the former is the correct Node.js convention.

@aurbano
Copy link
Owner

aurbano commented Mar 25, 2020

This wil be fixed once #105 is implemented

@aurbano aurbano closed this as completed Mar 25, 2020
@FoxBearBear
Copy link

Why is this closed @aurbano if it's not fixed yet?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants