dotkernel / dot-errorhandler
PSR-15 error handler middleware with optional PSR-3 logging
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- ext-mbstring: *
- laminas/laminas-stdlib: ^3.21
- laminas/laminas-stratigility: ^4.3.1
- mezzio/mezzio: ^3.28.1
- psr/container: ^1.1 || ^2.0
- psr/http-message: ^1.0 || ^2.0
- psr/http-server-handler: ^1.0.2
- psr/http-server-middleware: ^1.0.2
- psr/log: ^2.0 || ^3.0
Requires (Dev)
- boundwize/structarmed: ^0.18.10
- dotkernel/dot-log: ^5.3
- laminas/laminas-coding-standard: ^3.1.0
- laminas/laminas-diactoros: ^3.8.0
- phpstan/phpstan: ^2.2.5
- phpstan/phpstan-phpunit: ^2.0.18
- phpunit/phpunit: ^12.5.22
Suggests
- dotkernel/dot-log: PSR-3 logger that the shipped config/log.global.php.dist configures
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 13:29:43 UTC
README
dot-errorhandler is Dotkernel's PSR-15 compliant error handler, with optional logging through any PSR-3 logger.
Version History
Documentation
Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/
Badges
Adding the error handler
- Add the composer package:
composer require dotkernel/dot-errorhandler
- If you use the logger from
config/log.global.php.dist, also adddotkernel/dot-log; since version 6 it is no longer installed with this package:
composer require dotkernel/dot-log
- Add the config provider:
- in
config/config.phpadd\Dot\ErrorHandler\ConfigProvider - in
config/pipeline.phpadd\Dot\ErrorHandler\ErrorHandlerInterface::class- the interface is used as an alias to keep all error handling related configurations in one file
- in
If you need other error handlers, you should place them before dot-errorhandler in the pipeline; else it will not be able to catch errors. We recommend using just one error handler unless you have an error-specific handler.
- Configure the error handler as shown below.
In config/autoload/error-handling.global.php:
<?php use Dot\ErrorHandler\ErrorHandlerInterface; use Dot\ErrorHandler\LogErrorHandler; return [ 'dependencies' => [ 'aliases' => [ ErrorHandlerInterface::class => LogErrorHandler::class, ], ], 'dot-errorhandler' => [ 'loggerEnabled' => true, 'logger' => 'dot-log.default_logger', ] ];
loggerEnabled must be true or false, and logger must name a container service that implements Psr\Log\LoggerInterface.
A configuration example for the default logger can be found in config/log.global.php.dist.
config/error-handling.global.php.dist shows every option, including the extra request data you can log; its header settings mask authorization and proxy-authorization by default.
Upgrading from an earlier version? See the upgrade guide.
When configuring the error handler in your application, you can choose between two classes:
Dot\ErrorHandler\LogErrorHandler: for logging and displaying errorsDot\ErrorHandler\ErrorHandler: for displaying errors only
Both
LogErrorHandlerandErrorHandlerhave factories declared in the package'sConfigProvider. If you need a custom ErrorHandler, it must have a factory declared in the config, as in the below example:
Example:
<?php declare(strict_types=1); return [ 'dependencies' => [ 'factories' => [ \App\CustomErrorHandler::class => \App\CustomHandlerFactory::class, ], 'aliases' => [ \Dot\ErrorHandler\ErrorHandlerInterface::class => \App\CustomErrorHandler::class, ], ], 'dot-errorhandler' => [ 'loggerEnabled' => true, 'logger' => 'dot-log.default_logger', ], ];
Config examples can be found in this project's config directory.