NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

Provider error responses and unreachable APIs never abort a lookup — they count as a miss and the pipeline moves on. The package throws for configuration problems (an unknown provider, a missing or corrupt MaxMind database), invalid input, a failed database refresh and the opt-in rate-limit ceiling. Every exception lives in RoundlyConsulting\Geolocation\Exceptions:

ExceptionThrown when
GeolocationExceptionAbstract base (a RuntimeException) — catch it to handle everything below.
UnknownProviderExceptionA name passed to using(), provider(), withToken() or withConfig() is neither in the providers map nor registered via extend(), or a providers entry has no name.
ProviderUnavailableExceptionA bundled HTTP provider can’t reach its API (timeout, DNS failure, refused connection). The manager catches it and asks the next provider; you meet it as LocationResolutionFailed’s error. Carries ->provider; the message is redacted.
DatabaseUpdateExceptionupdateDatabase() or geolocation:db:update has no license key or path, the download fails (HTTP error, timeout, unreachable host) or the archive can’t be unpacked. The license key is redacted from the message.
InvalidCoordinatesExceptionLatitude outside [-90, 90], longitude outside [-180, 180], or a non-Coordinates value assigned to the cast.
DatabaseNotFoundExceptionThe MaxMind database provider is enabled but the .mmdb file is missing, unreadable or no path is set.
InvalidDatabaseExceptionThe .mmdb file is corrupt — missing metadata, truncated, malformed or an unsupported record size.
RateLimitExceededExceptionA provider’s limiter would wait longer than its max_wait. Carries ->provider and ->retryAfterSeconds().

A malformed config value — a typo’d switch, a non-integer timeout, an unknown rate-limit window — throws package-toolkit’s RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException naming the key instead. It is not a GeolocationException, so catching GeolocationException never hides a misconfiguration.

Connection failures

When a provider can’t be reached at all — a timeout, a DNS failure, a refused connection — Laravel’s HTTP client retries per the provider’s retry settings, then the provider throws ProviderUnavailableException and the manager skips to the next provider. If nothing answers, the lookup returns null and LocationResolutionFailed names the last unreachable provider and its error. distance() skips an unreachable provider the same way, and distanceMatrix() degrades every cell to null.

API keys and the MaxMind license key never appear in exception messages: they are redacted, and the transport exception — whose message quotes the full request URL — is not chained as previous.

Catch GeolocationException to handle everything in one place:

use RoundlyConsulting\Geolocation\Exceptions\GeolocationException;

try {
    $location = Geolocation::locateRequest();
} catch (GeolocationException $e) {
    report($e);   // missing or corrupt .mmdb, rate-limit ceiling, unknown provider...
    $location = null;
}

batch() already catches per item and turns any exception into null for that IP.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.