octonode icon indicating copy to clipboard operation
octonode copied to clipboard

Rate Limit check needed before parsing response body

Open dieter-smt opened this issue 8 years ago • 1 comments

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 {

  }
}

dieter-smt avatar Jan 26 '17 07:01 dieter-smt

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 avatar Mar 03 '17 20:03 pksunkara