diff --git a/src/HttpKernel/BaseKernel.php b/src/HttpKernel/BaseKernel.php index 2226d9e..3d4dd20 100644 --- a/src/HttpKernel/BaseKernel.php +++ b/src/HttpKernel/BaseKernel.php @@ -24,6 +24,7 @@ use ArrayAccess\TrayDigita\L10n\Translations\Adapter\Gettext\PoMoAdapter; use ArrayAccess\TrayDigita\L10n\Translations\Adapter\Json\JsonAdapter; use ArrayAccess\TrayDigita\L10n\Translations\Interfaces\TranslatorInterface; +use ArrayAccess\TrayDigita\Middleware\ErrorMiddleware; use ArrayAccess\TrayDigita\Middleware\RoutingMiddleware; use ArrayAccess\TrayDigita\PossibleRoot; use ArrayAccess\TrayDigita\Util\Filter\Consolidation; @@ -837,6 +838,14 @@ final public function init() : static } catch (Throwable) { $debugMiddleware = new DebuggingMiddleware($container); } + try { + $errorMiddleware = ContainerHelper::resolveCallable( + ErrorMiddleware::class, + $container + ); + } catch (Throwable) { + $errorMiddleware = new ErrorMiddleware($container); + } // @dispatch(kernel.initConfig) $manager->dispatch('kernel.initConfig', $this); } finally { @@ -876,8 +885,8 @@ final public function init() : static KernelCommandLoader::register($this); // registering debug middleware at the first middleware - $httpKernel->addMiddleware($debugMiddleware); - + $httpKernel->addDeferredMiddleware($debugMiddleware); + $httpKernel->addDeferredMiddleware($errorMiddleware); return $this; }