Exceptions
Every package exception extends ReportsException, itself a RuntimeException, so you can catch them individually or together:
| Exception | Thrown when | Carries |
|---|---|---|
DuplicateReportException | prevent_duplicates blocks a repeat report. | existing |
InvalidStatusTransitionException | A status move — changeStatus(), review(), close(), changeStatusTo(), resolve or reject — is undeclared while strict_transitions is on. | report, from, to |
UnknownReportReasonException | The reason is not in the allowed list and allow_unknown_reasons is false. | slug, allowed |
MissingModeratorsException | Reports::moderate(...)->open() is called without moderators. | — |
ModeratorRequiredException | A report under moderation is resolved, rejected or moved out of the open statuses by anyone but a named moderator (or a delegate of one), or without an actor. Nothing is written. | report, actor |
MissingPruneWindowException | Reports::prune() runs with no $days and no prune_after_days. | — |
ReportsException | Base class of all of the above; extends RuntimeException. | — |
use RoundlyConsulting\Reports\Exceptions\ReportsException;
use RoundlyConsulting\Reports\Exceptions\UnknownReportReasonException;
try {
Reports::report($post)->by($user)->for($slug)->create();
} catch (UnknownReportReasonException $e) {
$e->slug; // the rejected slug
$e->allowed; // list<string> — the allowed slugs
} catch (ReportsException $e) {
// any other package exception, e.g. DuplicateReportException
}Creating a report without a subject — a PendingReport started with Reports::from() and no about() — throws a plain LogicException.
Two failures come from the packages underneath and do not extend ReportsException: an invalid config value — threshold, prune_after_days, the moderation defaults, duplicate_scope, table, reasons, key_type or model (see Configuration) — throws the toolkit’s InvalidConfigurationException, and opening moderation with an unsaved moderator or a quorum above the moderator count throws the approvals engine’s InvalidApprovalRequestException.
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.