question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Catching rate limit exceptions

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jskeetcommented, Feb 28, 2018

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.

0reactions
jskeetcommented, Feb 28, 2018

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, use FetchFromUri or FetchFromUriAsync instead.

Finally trying to provoke the error so I can confirm its status.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found