aurbano / robinhood-node

:chart_with_upwards_trend: NodeJS client for Robinhood Trading :fire:

Home Page:https://aurbano.github.io/robinhood-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught exception in _login(callback) when request was throttled

chooikw opened this issue · comments

Code being executed:

if (!body.access_token) {
          throw new Error(
              "token not found " + JSON.stringify(httpResponse)
          )
      }

Expected result

Avoid mixing throw exception with result callback handler.

Actual behaviour

Error: token not found {"statusCode":429,"body":{"detail":"Request was throttled. Expected available in 51 seconds."},"headers":{"date":"Tue, 26 Feb 2019 14:38:09 GMT","content-type":"application/json","content-length":"69","connection":"keep-alive","server":"nginx","retry-after":"51","allow":"POST, OPTIONS","x-robinhood-api-version":"0.0.0","content-security-policy":"default-src 'none'","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","x-xss-protection":"1; mode=block"},"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}}}

Reproducing

  1. Launch one instance, make alot of requests to robinhood to trigger the request throttling.
  2. Launch another instance, it will fail at Robinhood initialization.

Workaround

I have to add following code before initializing Robinhood to catch the exception

process.on('uncaughtException', function(err) {
                // handle the exception here
              });

In robinhood v1 this is the only solution as you say. #105 will introduce error reporting in the callbacks and in promises.