clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

Access to Rate Limiting error response headers #23

Closed alexlatchford closed 7 years ago

alexlatchford commented 7 years ago

I'm trying to respect the Rate Limiting defined in the docs: https://clearbit.com/docs#rate-limiting

Catching the error thrown on a rate_limit call I get:

{"message":"Rate limit exceeded. Limit is 5 concurrent requests.","type":"rate_limit","body":{"error":{"type":"rate_limit","message":"Rate limit exceeded. Limit is 5 concurrent requests."}},"statusCode":400}

There doesn't seem to be any easy access to the response headers here, any chance I could ask you to add this please. I'll just use an exponential backoff (maxing out at 8s) for now but would be great to get access to the Retry-After header in particular to optimise the wait period.

Also looks like either the API is throwing the wrong code or the client lib is transforming it to 400, the docs suggest it should be returning a 429.

Thanks, Alex

alexlatchford commented 7 years ago

Hey @robholland any news on this one?

robholland commented 7 years ago

@alexlatchford The error isn't time based, you are being limited to 5 concurrent requests, so we can't give you an indication of when you'll be able to connect again. You'll need to manage that on your side.

I've filed a PR to fix our return code, sorry about that.