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

Every package exception lives in RoundlyConsulting\Approvals\Exceptions and extends ApprovalsException, itself a RuntimeException — one catch covers the whole family:

ExceptionThrown when
ClosedApprovalRequestExceptionA decision or withdrawal — approve, reject, toggle, ask or cancel — 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). Its $request property is that request.
IncompletePendingApprovalExceptionA builder decides without an actor (missingActor) or an approvable (missingApprovable).
InvalidApprovalModelExceptionA configured model class doesn’t extend the expected base model (forClass).
InvalidApprovalRequestExceptionA 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).
InvalidDelegationExceptionSelf-delegation (selfDelegation), a window that ends before it starts (endsBeforeStart), or ApprovalDelegation::revoke($at) with a moment in the future (futureRevocation).
InvalidStatusTransitionExceptionAn 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).
UnauthorizedApprovalExceptionThe 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).
UnknownWorkflowExceptionA 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 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.