Catching rate limit exceptions
See original GitHub issueI highly doubt I will reach the threshold of 400 reqs per second but just incase how should I handle any rate limit exceptions I might encounter, here is a sample of code I am using currently:
static void Main(string[] args)
{
var credential = GoogleCredential.FromFile(AppDomain.CurrentDomain.BaseDirectory + "license.json")
.CreateScoped(ImageAnnotatorClient.DefaultScopes);
var channel = new Grpc.Core.Channel(
ImageAnnotatorClient.DefaultEndpoint.ToString(),
credential.ToChannelCredentials());
var client = ImageAnnotatorClient.Create(channel);
// Load the image file into memory
var image = Image.FromUri("http://lincolnshiretoday.net/mag/wp-content/uploads/2017/07/high-street-lbig-web.jpg");
// Performs label detection on the image file
var labels = client.DetectLabels(image);
foreach (var label in labels)
{
// Description
// Score
Console.WriteLine(label.Description + " - " + label.Score);
Console.WriteLine(Environment.NewLine);
}
Console.ReadLine();
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to throw a custom exception in polly rate limit exceeds ...
I want to throw a custom error if the retry limit is exceeded. Does anyone know how to do it? c# · exception...
Read more >How to catch the rate limit exception? · Issue #10
I am using your limiter, which is great! However, I can't seem to redirect user to a custom page using the exception catching...
Read more >Best practices for avoiding rate limiting
If you regularly exceed the rate limit, update your code to distribute requests more evenly over a period of time. This is known...
Read more >How to Resolve ChatGPT Rate Limit Errors
It's a best practice to monitor exceptions that occur when interacting with any external API. For example, the API might be temporarily ...
Read more >Rate limiting best practices - WAF
A common use case is to limit the rate of requests performed by individual user agents. The following example rule allows a mobile...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Confirmed: the error status code is
ResourceExhausted
. I’d expect this to be consistent across APIs, and I know that’s the case for Speech for example.Closing as I think we’ve answered everything we can here - exactly how you handle that error is up to your application, as I mentioned before.
One side note by the way:
Image.FromUri
doesn’t load the image into memory. Instead, the URI is sent in the request. If you want to load the image data into memory and then send that in a request, useFetchFromUri
orFetchFromUriAsync
instead.Finally trying to provoke the error so I can confirm its status.