google-maps-services-java: Geocoding: API throws OverQueryLimitException instead of OverDailyLimitException

Environment details

  1. Geocoding API
  2. JDK: OpenJdk 1.8.0_212
  3. Library Version: 0.15.0

Steps to reproduce

  1. Set a daily limit of 1 in the api
  2. Execute more than one geocoding Command
  3. Check the class of the thrown exception

Should

A OverDailyLimitException is thrown

Is

A OverQueryLimitException is thrown

Code example

try {
  geocodingApi.geocode(geoApiContext, address).await();
} catch (ApiException e) {
  if (e instanceof OverDailyLimitException) {
    LOG.warn("The daily query limit has been reached for the apiKey {}", geocodingModule.getApiKey());
  } else if (e instanceof OverQueryLimitException) {
    LOG.warn("A rate limit has been reached for the apiKey {}, please try again in 1 minute", geocodingModule.getApiKey());
  } else {
    LOG.error("An API exception occurred while trying to geocode {} with the apiKey {}", address,  apiKey, e);
  }
}
...

Bug

The api currently returns

You have exceeded your daily request quota for this API. If you did not set a custom daily request quota, verify your project has an active billing account: http://g.co/dev/maps-no-account

instead of

You have exceeded your daily request quota for this API.

as expected and checked for in the ApiException class.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (16 by maintainers)

Commits related to this issue

Most upvoted comments

@PratikBorhade302 how is it going? Can I help you out somehow?

@PratikBorhade302 as soon as you limited the daily-quote, you should be able to reproduce the bug by executing at least 2 call to the api (e.g. executing this line twice: geocodingApi.geocode(geoApiContext, address).await();). This should throw the OverDailyLimitException which you are trying to reproduce.

@PratikBorhade302 Sure, go ahead an use it. The daily limit can be set at this page of your project: https://console.cloud.google.com/google/maps-apis/quotas after selecting the project and the Geocoding API you have three accordeons, at the bottem of the third (Requests) you should see the limits and be able to edit them.

Apologies for chiming in just now. I’ve had limited bandwidth and have not had the chance to look into this issue.

@PratikBorhade302, the best way to test your change would be to add a new test (e.g. ApiExceptionTest.java) within this package https://github.com/googlemaps/google-maps-services-java/tree/master/src/test/java/com/google/maps and validate that the correct exception is raised. If you send a pull request with the changes, I’ll review it. I appreciate the help.