Skip to content

getApiCallResult() recurses on successful responses, causing unnecessary API calls #21

@schmigotzki

Description

@schmigotzki

Bug Description

GeoService::getApiCallResult() is intended to retry the Google Maps Geocoding API call when an OVER_QUERY_LIMIT response is received but the retry condition is inverted causing the method to recurse on successful (OK) responses which is the exact opposite of the intended behaviour.

Steps to Reproduce

Configure maxRetries to any value greater than 0 (e.g. 10, which is already the default) in the extension configuration and trigger a geocoding request. Even when the API responds successfully with status OK, the method will recurse maxRetries additional times, resulting in maxRetries + 1 total API calls (e.g. 11 calls instead of 1).

Root Cause

Condition in getApiCallResult():

if (($result['status'] ?? '') === 'OVER_QUERY_LIMIT' || $remainingTries <= 0) {
    return $result;
}
return $this->getApiCallResult($url, $remainingTries - 1);

This returns early when OVER_QUERY_LIMIT is received and recurses when status is OK. The operator should be !==, not ===.

Proposed Fix

Change === to !==:

- if (($result['status'] ?? '') === 'OVER_QUERY_LIMIT' || $remainingTries <= 0) {
+ if (($result['status'] ?? '') !== 'OVER_QUERY_LIMIT' || $remainingTries <= 0) {
       return $result;
   }
   return $this->getApiCallResult($url, $remainingTries - 1);

With this fix the method returns immediately on a successful OK response and only retries when OVER_QUERY_LIMIT is returned and retries remain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions