Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bermudaphp/error-handler

The ErrorHandler middleware handles errors and generates a psr-7 compliant response
https://github.com/bermudaphp/error-handler

error-handling errors middleware php psr-15 psr-7

Last synced: 15 days ago
JSON representation

The ErrorHandler middleware handles errors and generates a psr-7 compliant response

Awesome Lists containing this project

README

        

# Install
```bash
composer require bermudaphp/error-handler
````
# Usage
```php
$generator = new ErrorResponseGenerator($psr17ResponseFactory, new WhoopsErrorGenerator($psr17ResponseFactory));
$generator->addGenerator($myConcreteErrorResponseGenerator);
$errorHandler = new ErrorHandlerMiddleware(new ErrorHandler($generator));
$pipeline->pipe($errorHandler); // Add ErrorHandlerMiddleware at the beginning of the middleware queue
````
# Event listening
```php
$errorListenerInterfaceInstance = new LogErrorListener($logger);
$errorHandler->on($errorListenerInterfaceInstance);
````
# ServerErrorEvent
```php
$request = $event->serverRequest;
$exception = $event->throwable;
````