Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Rate Limit check needed before parsing response body #264

Open
dieter-smt opened this issue Jan 26, 2017 · 1 comment
Open

Rate Limit check needed before parsing response body #264

dieter-smt opened this issue Jan 26, 2017 · 1 comment

Comments

@dieter-smt
Copy link

Octonode client.repo() method does return {"message":"Unexpected token <", ..... } when GitHub call hits the GitHub rate limit. This is somewhast misleading. It took me quite some time to figure I have a GitHub rate limit issue.

Here's a pseudo code sample showing how I ran into the issue ....

var ghrepo=client.repo(<orgname>+'/'+<reponame>);
ghrepo.info( function(err,info) {
   if (err) {

/*
 info contains the following message when GitHub rate limit is exceeded
     {"message":"Unexpected token <", .....         }
 Probable root cause is method Client.prototype.errorHandle(res,body,callback).
 It tries to parse body in the GitHub response and expects it to be JSON format.
 The response body in case GitHub rate limit is reached looks like the following:

<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

This cause the JSON.parse(body ...  ) to fail with 'Unexpected token >....' which is then returned to the caller of ghrepo.info() .  Returning the 403 FORBIDDEN might be more appropriate.
*/

   }
  else {

  }
}
@pksunkara
Copy link
Owner

We should add a rate limit check after every response return for the client and before parsing it. Would you be willing to work on this?

@pksunkara pksunkara changed the title Misleading error {"message":"Unexpected token <" when GitHub returns HTTP 403 because of rate limit Rate Limit check needed before parsing response body Mar 3, 2017
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

2 participants