All packages
Approvals for Laravel
Exceptions
Every package exception lives in RoundlyConsulting\Approvals\Exceptions and extends ApprovalsException, itself a RuntimeException — one catch covers the whole family:
| Exception | Thrown when |
|---|---|
ChangedApprovalSubjectException | A decision — approve, reject, ask or toggling on — reached a round whose subject’s fingerprint changed since it opened, with fingerprint.on_change set to refuse or void (for). $request is the round; $voided says whether it was voided on the way. Nothing is recorded. Since 2.2.0. |
ClosedApprovalRequestException | A decision, a withdrawal or a replacement of approvers — approve, reject, toggle, ask, cancel, replaceApprovers() or replaceFlatApprovers() — reaches a closed request (approved, rejected, cancelled or expired), pinned with within() even while a later round is open, or because all the subject’s requests are closed (for); replaceApprovers() or replaceFlatApprovers() on a round still pending but past its expiry, which it does not lapse (overdue); a decision that reaches the round’s lock after voidIfChanged() or a closing recheckThreshold() closed it. Its $request property is that request. |
IncompletePendingApprovalException | A builder decides without an actor (missingActor) or an approvable (missingApprovable). |
InvalidApprovalModelException | A configured model class doesn’t extend the expected base model (forClass). |
InvalidApprovalRequestException | A decision — toggle() included — or close() is pinned to another subject’s request (foreignSubject); a request builder gets both from() and stages() (mixedApprovers); workflow() follows from(), rule(), any(), quorum(), weighted(), stages() or continueOnRejection(), which the preset defines (definedByWorkflow); ask() follows weight() (weightOnAsk); reject() follows an expiry (expiryOnReject); cancel() follows weight() or an expiry (settingsOnCancel); close() follows because() (reasonOnClose), or as(), weight() or an expiry (settingsOnClose); an approver is unsaved (unsavedApprover); a request needs more approvals than it names (moreRequiredThanNamed); a quorum is below 1 (thresholdBelowOne) or out of the approvers’ reach (unreachableThreshold); a request or stage its rule could never approve because it needs no approvals — e.g. an unnamed request under the default Unanimous rule (needsNoApprovals). replaceApprovers() also refuses as(), because(), weight() or an expiry (settingsOnReplace), an empty list (noReplacementApprovers), a subject that never had a round (noRound), a flat round (notStaged), a stage the round doesn’t have (unknownStage) or that isn’t the open one (stageNotOpen), an approver who already decided the stage (alreadyDecided), and a list under which the decisions already made would settle the stage at once (replacementSettlesStage). Since 2.2.0 also: an excluded actor named as an approver at open or by a replacement (excludedApprover), an unsaved actor passed to excluding() (unsavedExcludedActor), a fingerprint longer than 255 characters (fingerprintTooLong), replaceFlatApprovers() on a staged round (staged), with an approver who already decided the round (alreadyDecidedRound) or a list under which the round would settle at once (replacementSettlesRound), and replaceFlatApprovers(), voidIfChanged() or recheckThreshold() with as(), because(), weight() or an expiry (settingsOnSubjectCall). |
InvalidDelegationException | Self-delegation (selfDelegation), a window that ends before it starts (endsBeforeStart), or ApprovalDelegation::revoke($at) with a moment in the future (futureRevocation). |
InvalidStatusTransitionException | An illegal status transition on the Approval model (between), or close() with an outcome other than Cancelled or Expired — even when no round is open (notAClosingOutcome), or recheckThreshold() asked to close with an outcome other than Cancelled or Rejected (notAnUnreachableOutcome). |
UnauthorizedApprovalException | The authorization gate denies the actor (forActor), or the actor is not a named approver of the request or its open stage, nor a delegate of one (notAnApprover) — also when replaceApprovers() or replaceFlatApprovers() dropped the actor, or the approver it acts for, while its decision was in flight. Also when the actor is excluded from deciding (excluded) or would decide for an excluded approver (excludedPrincipal). |
UnknownWorkflowException | A workflow preset is missing (named) or malformed (invalid). |
use RoundlyConsulting\Approvals\Exceptions\ApprovalsException;
use RoundlyConsulting\Approvals\Exceptions\ClosedApprovalRequestException;
use RoundlyConsulting\Approvals\Exceptions\UnauthorizedApprovalException;
use RoundlyConsulting\Approvals\Facades\Approvals;
try {
Approvals::for($post)->as($user)->approve();
} catch (UnauthorizedApprovalException $e) {
// the gate denied this actor, or the request does not name it
} catch (ClosedApprovalRequestException $e) {
// the round is over — $e->request is the closed request
} catch (ApprovalsException $e) {
// any other approvals error
}Each exception is built by the named static factory shown in brackets above, which is handy when you assert messages in tests.
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.