# PHP package for error handling

The HttpSoft\ErrorHandler package implements Psr\Http\Server\MiddlewareInterface and Psr\Http\Server\RequestHandlerInterface.

This package requires PHP version 7.4 or later.

Package installation:

composer require httpsoft/http-error-handler

Source code on GitHub.

# API

Interfaces:

# Usage

use HttpSoft\ErrorHandler\ErrorHandler;
use HttpSoft\ErrorHandler\ErrorHandlerMiddleware;

/**
 * @var Psr\Http\Message\ServerRequestInterface $request
 * @var Psr\Http\Server\RequestHandlerInterface $handler
 * @var HttpSoft\ErrorHandler\ErrorListenerInterface $listener
 * @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator
 */

// Usage ErrorHandler
$errorHandler = new ErrorHandler($handler, $responseGenerator);
$errorHandler->addListener($listener);
$response = $errorHandler->handle($request);

// Usage ErrorHandlerMiddleware
$errorHandler = new ErrorHandlerMiddleware($responseGenerator);
$errorHandler->addListener($listener);
$response = $errorHandler->process($request, $handler);

Detailed description of using HttpSoft\ErrorHandler\ErrorHandler see here.

Detailed description of using HttpSoft\ErrorHandler\ErrorHandlerMiddleware see here.

Detailed description of using HttpSoft\ErrorHandler\ErrorHandlerTrait see here.