phpbotgram

ErrorsMiddleware extends BaseMiddleware
in package

FinalYes

Top-of-chain dispatcher middleware (mirror of aiogram's `aiogram.dispatcher.middlewares.error.ErrorsMiddleware`) that **routes real exceptions to the `errors` observer**.

Any Throwable is wrapped in an ErrorEvent and forwarded to the dispatcher's errors observer via the $errorsTrigger closure.

  • If the observer claims the error (returns a truthy non-sentinel value), that value becomes the middleware's return value.
  • If the observer returns REJECTED, the middleware collapses it to UNHANDLED (parity with upstream's if response is REJECTED: return UNHANDLED).
  • If the observer returns UNHANDLED or null, the original exception is re-raised so the caller sees it.

Signalling exceptions are NOT handled here. SkipHandlerException and CancelHandlerException are caught by TelegramEventObserver::triggerCore at the per-handler boundary (Fix C1) so a Bases::skip() inside a handler abandons that ONE handler and falls through to the next on the same observer — parity with upstream's aiogram/dispatcher/event/telegram.py:127-128 per-handler except SkipHandler: continue. The previous behaviour of catching them in this top-of-chain middleware caused the WHOLE observer dispatch to collapse to UNHANDLED on a single Bases::skip(), deviating from upstream's semantics.

The trigger is wired by Dispatcher::__construct. The event_update kwarg is injected by the Dispatcher (Task 3.10) before this middleware runs — defensive code re-raises if it's absent or non-Update, because the errors observer needs the original Update to filter on update shape.

Table of Contents

Constants

EVENT_UPDATE_KEY  : string = 'event_update'
Canonical name for the `Update` slot in the dispatcher's `$data` bag.

Properties

$errorsTrigger  : Closure|null

Methods

__construct()  : mixed
__invoke()  : mixed

Constants

EVENT_UPDATE_KEY

Canonical name for the `Update` slot in the dispatcher's `$data` bag.

public string EVENT_UPDATE_KEY = 'event_update'

The Dispatcher (Task 3.10) writes the incoming Update to this key before ErrorsMiddleware runs; the errors observer's filters bind the same name via CallableObject reflection.

Properties

Methods

__construct()

public __construct([callable(string, ErrorEvent, array<string, mixed>): mixed|null $errorsTrigger = null ]) : mixed
Parameters
$errorsTrigger : callable(string, ErrorEvent, array<string, mixed>): mixed|null = null

Trigger callable that invokes the dispatcher's errors observer. Signature: ($updateTypeName, $errorEvent, $data) → mixed. Task 3.8 wires this to the real TelegramEventObserver; for now callers may pass null (the default), in which case every non-signalling exception is re-raised without observer dispatch.

__invoke()

public __invoke(callable(object, array<string, mixed>): mixed $handler, object $event, array<string, mixed> $data) : mixed
Parameters
$handler : callable(object, array<string, mixed>): mixed
$event : object
$data : array<string, mixed>
On this page

Search results