Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/bermudaphp/error-handler
- Owner: bermudaphp
- License: mit
- Created: 2020-06-17T18:31:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-11T20:32:43.000Z (almost 2 years ago)
- Last Synced: 2024-11-10T10:07:59.250Z (2 months ago)
- Topics: error-handling, errors, middleware, php, psr-15, psr-7
- Language: PHP
- Homepage:
- Size: 304 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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;
````