MitjaBezensek / SharpBucket

SharpBucket is a .Net wrapper for the Bitbucket's REST API.
MIT License
67 stars 60 forks source link

When I hit the rate limits of the API SharpBucket handle very badly the response #108

Closed mnivet closed 5 years ago

mnivet commented 5 years ago

If I do a lot of API requests I may reach the rate limit setupt by bitucket. In that case BitBucket return an HTTP 429 error response which is not handle at all by SharpBucket and start to an an erratic behavior since it try to interpret the result like if it was an HTTP 200 response.

Exemple of the BitBucket response:

HTTP/1.1 429 Unknown Status Code
Server: nginx
Vary: Authorization
Cache-Control: no-cache, no-store
Content-Type: text/plain
X-OAuth-Scopes: account, team, pullrequest, issue, snippet, webhook
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Fri, 25 Jan 2019 14:55:24 GMT
X-Served-By: app-161
X-Static-Version: 81e1c2138b0b
ETag: "62dcd5481fd29816ecc5ae00be2da0b0"
X-Render-Time: 0.0162138938904
X-Credential-Type: oauth1
X-Accepted-OAuth-Scopes: repository
Connection: Keep-Alive
X-Version: 81e1c2138b0b
X-Request-Count: 447
X-Frame-Options: SAMEORIGIN
Content-Length: 46

Rate limit for this resource has been exceeded

NB: the X-Request-Count header seems to depends on the X-Served-By, but it doesn't seems to be of any help for this issue

mnivet commented 5 years ago

109 allow consumers to catch exceptions and implements their own re-try logic

So it's no more a bug, it may eventually be re-opened as a feature request but it's not a priority since it's hard to provide a retry logic that would please to everybody, which means that it would be more an injection point that a consumer can use to provide it's own retry logic, than something natively provided