Skip to content

Exceptions

Every exception thrown by the package extends Aanfarhan\Chatbot\Exceptions\ChatbotException, an abstract class extending RuntimeException.

php
namespace Aanfarhan\Chatbot\Exceptions;

abstract class ChatbotException extends \RuntimeException
{
    abstract public function code(): string;
    abstract public function isRetryable(): bool;
}

The class hierarchy, the code() return values, and the isRetryable() semantics are part of the public contract. The getMessage() text is not.

Hierarchy

ChatbotException (abstract)
├── ChatbotConfigurationException
├── ChatbotContentBlockedException
├── ChatbotProviderException
├── ChatbotQuotaExceededException
├── ChatbotTimeoutException
├── ChatbotTokenCapExceededException
├── ForbiddenToolArgumentException
└── InvalidEnvelopeException (abstract)
    ├── ExpiredEnvelopeException
    ├── MismatchedEnvelopeException
    └── TamperedEnvelopeException

Reference

Classcode()isRetryable()When
ChatbotConfigurationExceptionconfiguration_errorfalseMisconfigured provider URL, missing API key, malformed channel block.
ChatbotContentBlockedExceptioncontent_blockedfalseContent filter rejected the request or response.
ChatbotProviderExceptionprovider_errorper-instanceThe upstream LLM returned a non-2xx. Constructor accepts bool $retryable and ?Throwable $previous.
ChatbotQuotaExceededExceptionquota_exceededfalseDailyUsageTracker exhausted chatbot.daily_quota.* for the user.
ChatbotTimeoutExceptiontimeouttrueStream exceeded chatbot.stream_duration, or a tool exceeded chatbot.tools.default_timeout.
ChatbotTokenCapExceededExceptiontoken_cap_exceededfalseA single user message alone exceeds chatbot.token_cap.
ForbiddenToolArgumentExceptionforbidden_tool_argumentfalseTool registration declared an identity-shaped parameter name (user_id, etc.).
InvalidEnvelopeException (abstract)invalid_envelopefalseBase for envelope verification failures.
ExpiredEnvelopeExceptioninvalid_envelopefalseThe envelope is past its TTL.
MismatchedEnvelopeExceptioninvalid_envelopefalseThe envelope was minted for a different route / channel / user.
TamperedEnvelopeExceptioninvalid_envelopefalseHMAC signature mismatch.

Outside the hierarchy

InvalidExtractorPayloadException (Aanfarhan\Chatbot\Exceptions\InvalidExtractorPayloadException) extends \RuntimeException directly — it is not a ChatbotException. It is thrown when a client-extractor payload fails internal validation and is caught by MessagesController, which turns it into a 422 response. You will not encounter it in normal application code.

Where they surface

ExceptionSurface
InvalidEnvelopeException familyHTTP 403 from POST /chatbot/messages.
Everything elseSSE error event on the open stream, code field matches ->code(), retryable matches ->isRetryable().

Usage

Match on ->code(), never on ->getMessage():

php
use Aanfarhan\Chatbot\Exceptions\ChatbotException;

try {
    // ...
} catch (ChatbotException $e) {
    match ($e->code()) {
        'quota_exceeded'    => $this->upsellPlan(),
        'invalid_envelope'  => $this->log->warning('possible tampering'),
        default             => report($e),
    };
}

Catching ChatbotException itself catches every package exception.

Released under the MIT License.