Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

Xero.NetStandard.OAuth2 - Handle API rate limit

Started by Yoshitaka Sawada -   in Wrapper libraries

We are migrating our Web app from OAuth1.0 to 2.0.

In OAuth1.0, we catch RateExceededException to handle API rate limit.
But it does not exist in OAuth2.0 SDK.

Is there any specific exception thrown or any error code?

Please advise how to handle API rate limit.

Thanks in advance,
Yoshitaka
I dealt with the same frustration for months, having to deal with specifically the minute rate limit. The problem is Oauth2 C# wrapper does not convert the correct exception from the API, so we can retry reactively .

What I did which worked greatly but is till not 100% fool proof, is to create another repository that wraps the Api class (AccountAPI) for example.

This repository class handles 2 things, first is for every response, it looks at the headers and I check the X-Min-Limit value, if its anything less than 5, I let the thread sleep for the duration of that minute. For example, I hit 5 at 00:01:45, it waits 15seconds before returning a response. It is a more proactive approach, so the next request will be made on the next minute, by the time the Min count is reset back to 0.

Second, it has a retry mechanism with a randomised "wait value" between a couple of seconds to up to 3minutes. This is to handle a scenario where 100 requests fail, and retry in the same exact time and never be able to complete.
 

Jeff Victorino  

Hi Jeff,
Thanks for your reply.
I'll try your idea.
 

Yoshitaka Sawada