Exceptions
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:
| Exception | Thrown when |
|---|---|
GeolocationException | Abstract base (a RuntimeException) — catch it to handle everything below. |
UnknownProviderException | A 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. |
ProviderUnavailableException | A 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. |
DatabaseUpdateException | updateDatabase() 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. |
InvalidCoordinatesException | Latitude outside [-90, 90], longitude outside [-180, 180], or a non-Coordinates value assigned to the cast. |
DatabaseNotFoundException | The MaxMind database provider is enabled but the .mmdb file is missing, unreadable or no path is set. |
InvalidDatabaseException | The .mmdb file is corrupt — missing metadata, truncated, malformed or an unsupported record size. |
RateLimitExceededException | A 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 cryptoBy 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.