PHPackages                             samuelgfeller/slim-error-renderer - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. samuelgfeller/slim-error-renderer

ActiveProject[Debugging &amp; Profiling](/categories/debugging)

samuelgfeller/slim-error-renderer
=================================

Slim 4 error handling middleware and exception page renderer

1.3.0(3mo ago)11.7k—0%3MITPHPPHP ^8.2CI passing

Since Apr 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/samuelgfeller/slim-error-renderer)[ Packagist](https://packagist.org/packages/samuelgfeller/slim-error-renderer)[ Fund](https://ko-fi.com/samuelgfeller)[ RSS](/packages/samuelgfeller-slim-error-renderer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (3)

Slim Error Renderer
===================

[](#slim-error-renderer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a766785d26515bbabc4b8b14a567f3dfb4266af97e21d30aedab58848108e7cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73616d75656c6766656c6c65722f736c696d2d6572726f722d72656e64657265722e737667)](https://packagist.org/packages/samuelgfeller/slim-error-renderer)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/samuelgfeller/slim-error-renderer/actions/workflows/build.yml/badge.svg)](https://github.com/samuelgfeller/slim-error-renderer/actions)[![Total Downloads](https://camo.githubusercontent.com/6cc344c0bdbb66d758888b8ec8d4f02792ed00fc5683b77e91fc612eec053e22/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d75656c6766656c6c65722f736c696d2d6572726f722d72656e64657265722e737667)](https://packagist.org/packages/samuelgfeller/slim-error-renderer/stats)

This package provides an alternative to the default Slim error handler and renderer.
It renders a styled error details page with the stack trace and the error message or a prod error page for production.

Custom error page renderers can be created to change the design of the error pages by implementing the `ErrorDetailsPageRendererInterface`or `ProdErrorPageRendererInterface`.

It also provides a [middleware](#exception-heavy-middleware) to make the project "exception-heavy", which means that it will throw exceptions with a stack trace for notices and warnings during development and testing like other frameworks such as Laravel or Symfony.

Preview
-------

[](#preview)

ExceptionWarning and NoticeProd error page[![](https://camo.githubusercontent.com/ed4b1223b3e0c9083fea88e3a88966ee839b94710f92a664e77a157474dd3d21/68747470733a2f2f692e696d6775722e636f6d2f5433564c3264452e706e67)](https://camo.githubusercontent.com/ed4b1223b3e0c9083fea88e3a88966ee839b94710f92a664e77a157474dd3d21/68747470733a2f2f692e696d6775722e636f6d2f5433564c3264452e706e67)[![](https://camo.githubusercontent.com/9c156378f6bfe1f081f58531e294d4cba3302e5b2e9d2ae6ea268b79c17d0711/68747470733a2f2f692e696d6775722e636f6d2f6770414f5578762e706e67)](https://camo.githubusercontent.com/9c156378f6bfe1f081f58531e294d4cba3302e5b2e9d2ae6ea268b79c17d0711/68747470733a2f2f692e696d6775722e636f6d2f6770414f5578762e706e67)[![](https://camo.githubusercontent.com/bea23d4ee4318bdf150a83c5106fc137e8226577ab9a565eaedfb401365119bd/68747470733a2f2f692e696d6775722e636f6d2f6d57625a4873692e706e67)](https://camo.githubusercontent.com/bea23d4ee4318bdf150a83c5106fc137e8226577ab9a565eaedfb401365119bd/68747470733a2f2f692e696d6775722e636f6d2f6d57625a4873692e706e67)Requirements
------------

[](#requirements)

- PHP 8.2+
- Composer
- A Slim 4 application

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

[](#installation)

### Install the package with composer

[](#install-the-package-with-composer)

Open a terminal in your project's root directory and run the following command:

```
composer require samuelgfeller/slim-error-renderer
```

### Configuration

[](#configuration)

The following configuration values are required in the settings. Modify accordingly in the development, production, and testing [configuration files](https://samuel-gfeller.ch/docs/Error-Handling#application-configuration).

File: `config/defaults.php`

```
$settings['error'] = [
    // Must be set to false in production
    'display_error_details' => false,
    // Whether to log errors or not
    'log_errors' => true,
];
```

### Add the error handling middleware to the Slim app

[](#add-the-error-handling-middleware-to-the-slim-app)

#### Container instantiation

[](#container-instantiation)

If you're using [Dependency Injection](https://samuel-gfeller.ch/docs/Dependency-Injection), add the error handling middleware to the container definitions (e.g. in the `config/container.php`) file. The `ExceptionHandlingMiddleware` constructor accepts the following parameters:

1. Required: instance of a response factory object implementing the `Psr\Http\Message\ResponseFactoryInterface`(see [here](https://github.com/samuelgfeller/slim-starter/blob/master/config/container.php) for a default implementation of a response factory)
2. Optional: instance of a PSR 3 [logger](https://samuel-gfeller.ch/docs/Logging)to log the error
3. Optional: boolean to display error details (documentation: [Error Handling](https://samuel-gfeller.ch/docs/Error-Handling))
4. Optional: contact email for the "report error" button on the error page
5. Optional: A custom prod error page renderer that implements `SlimErrorRenderer\Interfaces\ProdErrorPageRendererInterface`
6. Optional: A custom error details page renderer that implements `SlimErrorRenderer\Interfaces\ErrorDetailsPageRendererInterface`

```
