Exceptions
All package exceptions live in RoundlyConsulting\Contacts\Exceptions and extend ContactException:
| Exception | Thrown when |
|---|---|
ContactException | Abstract base (extends RuntimeException) — catch it to handle every package error. |
InvalidContactValue | add(), update() or sync() got a value that fails its kind’s rules after normalization or exceeds 255 characters — or a structured address on a contact that is not an address. |
InvalidVerificationToken | verification()->confirm() with a wrong token, when none was issued, or after the token was voided. |
VerificationAttemptsExceeded | The wrong guess that spent the token’s last attempt (max_attempts); the token is voided. Extends InvalidVerificationToken. |
VerificationExpired | The token matched but is past its TTL. |
PrimaryContactConflict | require_owner_for_primary is on and an ownerless contact is made primary. |
RelationshipException | relateTo() with a kind outside relationship_kinds, or a contact related to itself. |
use RoundlyConsulting\Contacts\Exceptions\ContactException;
try {
$user->addPhone($request->string('phone')->toString());
} catch (ContactException $e) {
return back()->withErrors(['phone' => $e->getMessage()]);
}InvalidContactValue, InvalidVerificationToken, VerificationAttemptsExceeded and VerificationExpired use the contacts::errors translations — invalid_value, structured_address_kind, invalid_verification_token, verification_attempts_exceeded and verification_expired — so you can reword or translate them by publishing contacts-translations. PrimaryContactConflict and RelationshipException carry plain English messages.
A malformed config value — a verification style, TTL, length or attempt count, the table, the country code, the model, key_type or a types / relationship_kinds entry — is not a ContactException: it throws RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException naming the key.
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.