Slim Framework 3 error handler built on top of the Whoops error handler

2.3.0 2018-05-17 17:11 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:23:48 UTC


Latest Stable Version Total Downloads Latest Unstable Version License

Slim Framework 3 error handler built on top of Whoops Error Handler


Use Composer to install Whoops into your project:

composer require dopesong/slim-whoops


  • PHP >=5.6.0
  • Whoops ^2.0

Usage With Slim 3

use Dopesong\Slim\Error\Whoops as WhoopsError;

include "vendor/autoload.php";

$app = new Slim\App();
$container = $app->getContainer();

$container['phpErrorHandler'] = $container['errorHandler'] = function($c) {
    return new WhoopsError();


Additional handlers

Custom handlers can be added to execute additional tasks. For example, you might want to log the error like so:

include "vendor/autoload.php";

use Whoops\Handler\Handler;
use Dopesong\Slim\Error\Whoops as WhoopsError;

$app = new Slim\App();
$container = $app->getContainer();

$container['phpErrorHandler'] = $container['errorHandler'] = function ($container) {
    $logger = $container['logger'];
    $whoopsHandler = new WhoopsError();

        function ($exception) use ($logger) {
            /** @var \Exception $exception */
            $logger->error($exception->getMessage(), ['exception' => $exception]);
            return Handler::DONE;

    return $whoopsHandler;