Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OVER_DAILY_LIMIT StatusCode not handled, results in ServiceResponseStatus.Unknown #143

Open
gbanister opened this issue Feb 2, 2019 · 3 comments

Comments

@gbanister
Copy link

DistanceMatrix documents top level status code OVER_DAILY_LIMIT:
https://developers.google.com/maps/documentation/distance-matrix/intro#StatusCodes

AsResponseStatus doesn't have a case for OVER_DAILY_LIMIT:
https://github.com/ericnewton76/gmaps-api-net/blob/develop/src/Google.Maps/JsonEnumTypeConverter.cs#L26

nor is it represented in the ServiceResponseStatus Enum
https://github.com/ericnewton76/gmaps-api-net/blob/develop/src/Google.Maps/ServiceResponseStatus.cs

@ericnewton76
Copy link
Owner

Thats an oversight. Thanks for reporting.

Were you running in a tight loop? We've always had plans to try to build an injectable or option for automatically backing off and retry but had some difference of opinions on how to implement.

@gbanister
Copy link
Author

gbanister commented Feb 2, 2019

That is funny you ask that. I was just looking into building retry logic into my app that uses your library and was looking into the response codes trying to figure out when I should retry and when I should not. I just now started thinking about it, but at first glance it seems UnKnown and OverQueryLimit would be the status to retry on, and optionally retry after a delay, especially for OverQueryLimit.

A useful interface to a retry API might look something like this:
var response = await distanceMatrixService
.ImediateRetryOnStatus(ServiceResponseStatus.Unknown, retrycount: 2)
.DelayedRetryOnStatus(ServiceResponseStatus.OverQueryLimit, msecdelay: 100, retrycount: 2)
.GetResponseAsync(request);

In the mean time, I'll settle on an extension method:

public static class GoogleMapsExtensions
{
    public static async Task<DistanceMatrixResponse> GetResponseWithRetryAsync(this DistanceMatrixService service, DistanceMatrixRequest request, int retryCount, int milSecDelay = 0)
    {
        var response = await service.GetResponseAsync(request);
    
        for (var i = 0; i < retryCount; i++)
        {
            if (response.Status == ServiceResponseStatus.OverQueryLimit || 
                response.Status == ServiceResponseStatus.Unknown)
            {
                Thread.Sleep(milSecDelay);
                response = await service.GetResponseAsync(request);
            }
        }
       return response;
    }

@ericnewton76
Copy link
Owner

There's more coming on that note. See the https://github.com/ericnewton76/gmaps-api-net/tree/fix/tests-using-snapshots branch (which I need to update with all the changes from base master branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants