PHPackages                             juliangut/slim-exception - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. juliangut/slim-exception

ActiveLibrary[HTTP &amp; Networking](/categories/http)

juliangut/slim-exception
========================

Slim HTTP exceptions and exception handling

3.0.1(2y ago)610.8k1[2 PRs](https://github.com/juliangut/slim-exception/pulls)BSD-3-ClausePHPPHP ^8.0CI passing

Since Jul 30Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/juliangut/slim-exception)[ Packagist](https://packagist.org/packages/juliangut/slim-exception)[ Docs](https://github.com/juliangut/slim-exception)[ GitHub Sponsors](https://github.com/juliangut)[ RSS](/packages/juliangut-slim-exception/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (23)Used By (0)

[![PHP version](https://camo.githubusercontent.com/6913801024bb6087176dec5fdb59388730a49b167cbb013222a7acbaecb48b7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e302d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/33864ad4cdf689e7db3a7738b86bc8df6a59d816a9afefa8b479b3280860fac8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a756c69616e6775742f736c696d2d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-exception)[![License](https://camo.githubusercontent.com/65c6bb405b538a94433cac57ca846ae650ba64ac223558de99ef6343470486e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a756c69616e6775742f736c696d2d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/juliangut/slim-exception/blob/master/LICENSE)

[![Total Downloads](https://camo.githubusercontent.com/6e621c27401e0bbb6130fb3b6aa6f08f005e6907e3318c3bd307c61d0e85c686/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a756c69616e6775742f736c696d2d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-exception/stats)[![Monthly Downloads](https://camo.githubusercontent.com/69ee352c52787d4669a09c4fefc0e2d35a1fedd68639f2ff441ca0fb9c12fc32/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a756c69616e6775742f736c696d2d657863657074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/juliangut/slim-exception/stats)

slim-exception
==============

[](#slim-exception)

Alternative Slim error handling with better response format negotiation, better exception logging and better development support

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require juliangut/slim-exception

```

Usage
-----

[](#usage)

Require composer autoload file

```
require './vendor/autoload.php';

use Jgut\Slim\Exception\Handler\ErrorHandler;
use Jgut\Slim\Exception\Whoops\Handler\ErrorHandler as WhoopsErrorHandler;
use Negotiation\Negotiator;
use Slim\Factory\AppFactory;
use Whoops\Run as Whoops;

// Instantiate the app
$app = AppFactory::create();

// ...

$callableResolver = $app->getCallableResolver();
$responseFactory = $app->getResponseFactory();
$logger = new Logger();

$errorHandler = $inDevelopment && class_exists(WhoopsErrorHandler::class)
    ? new WhoopsErrorHandler($callableResolver, $responseFactory, new Negotiator(), $logger)
    : new ErrorHandler($callableResolver, $responseFactory, new Negotiator(), $logger);

// Add Error Middleware
$errorMiddleware = $app->addErrorMiddleware($inDevelopment, true, true);
$errorMiddleware->setDefaultErrorHandler($errorHandler);

// ...

$app->run();
```

### Renderers

[](#renderers)

Custom error renderers are configured when using slim-exception error handlers. Fear not, out of the box ErrorHandler is a direct drop-in to change default Slim ErrorHandler

You can register your error renderers or completely change them

```
$errorHandler = new ErrorHandler($callableResolver, $responseFactory, new Negotiator());

// Set single error renderer
$errorHandler->setErrorRenderer('application/xhtml+xml', MyCustomHtmlRenderer::class);

// Completely replace error renderers
$errorHandler->setErrorRenderers(['text/html' => MyCustomHtmlRenderer::class]);
```

### Whoops

[](#whoops)

Developers deserve a better and more informative error handling while in development environment

[Whoops](https://github.com/filp/whoops) is a great tool for this purpose and its usage is integrated in this package. There is a special Whoops error handler which can be used as default exception handler for development

Given Whoops renderers are meant for development displayErrorDetails argument on `Slim\Interfaces\ErrorRendererInterface::__invoke` won't be considered and stacktrace will always be displayed

The example of how to include Whoops error handler is in the code above

For you to use this handler you'll need to require whoops first. Additionally, Symfony's var-dumper plays nice with whoops so require it too

```
composer require --dev filp/whoops
composer require --dev symfony/var-dumper

```

Handle all errors/exceptions
----------------------------

[](#handle-all-errorsexceptions)

In order to fully integrate error handling with the environment you can register ExceptionHandler globally. In this way any triggered and unhandled error will be captured and treated by the error handler

```
use Jgut\Slim\Exception\ExceptionHandler;
use Slim\Factory\AppFactory;

// Instantiate the app
$app = AppFactory::create();

// ...
// Create and register $errorHandler in error middleware

$request = Psr17ServerRequestFactoryInterface::createServerRequest();

$exceptionHandler = new ExceptionHandler($request, $errorHandler, $inDevelopment, true, true);
$exceptionHandler->registerHandling();

// ...

$app->run($request);

// This error will be captured and gracefully handled
trigger_error('This is embarrassing', \E_USER_ERROR);
```

Upgrade from 2.x
----------------

[](#upgrade-from-2x)

- Minimum PHP version is now 8.0
- Minimum Whoops version is now 2.15 as custom Inspector has been removed in favor of Whoop's frame filters

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/juliangut/slim-exception/issues). Have a look at existing issues before.

See file [CONTRIBUTING.md](https://github.com/juliangut/slim-exception/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

See file [LICENSE](https://github.com/juliangut/slim-exception/blob/master/LICENSE) included with the source code for a copy of the license terms.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance48

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 98.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~113 days

Recently: every ~238 days

Total

21

Last Release

932d ago

Major Versions

0.6 → 1.02018-10-04

1.x-dev → 2.02019-09-12

2.7 → 3.02023-10-19

PHP version history (5 changes)0.1PHP ^7.0

2.0PHP ^7.1

2.5PHP ^7.3|^8.0

2.6PHP ^7.4|^8.0

3.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (133 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

httpexceptionsslim-frameworkwhoopshttpslimexception

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juliangut-slim-exception/health.svg)

```
[![Health](https://phpackages.com/badges/juliangut-slim-exception/health.svg)](https://phpackages.com/packages/juliangut-slim-exception)
```

###  Alternatives

[chadicus/slim-oauth2

OAuth2 routes, middleware and utilities for use within a Slim Framework API

129365.9k3](/packages/chadicus-slim-oauth2)[chadicus/slim-oauth2-http

Bridge components for PSR-7 and bshaffer's OAuth2 Server http messages.

18455.2k7](/packages/chadicus-slim-oauth2-http)[mezzio/mezzio-hal

Hypertext Application Language implementation for PHP and PSR-7

20456.9k6](/packages/mezzio-mezzio-hal)[middlewares/error-handler

Middleware to handle http errors

14104.2k13](/packages/middlewares-error-handler)[mhndev/slim-file-response

Slim File Response

112.5k](/packages/mhndev-slim-file-response)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
