dmt-software/http-exception-middleware

psr-15 http exception middleware

1.1.0 2024-08-30 07:52 UTC

This package is auto-updated.

Last update: 2024-11-30 08:22:49 UTC


README

PSR-15 middleware to transform http exceptions from pavelsterba/http-exceptions to PSR-7 responses.

Installation

composer require dmt-software/http-exception-middleware

Usage

use DMT\Http\Exception\Middleware\HttpExceptionMiddleware;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

/** @var ResponseFactoryInterface $httpExceptionMiddleware */
$httpExceptionMiddleware = new HttpExceptionMiddleware($responseFactory);

/** @var ServerRequestInterface $request */
/** @var RequestHandlerInterface $handler */
$httpExceptionMiddleware->process($request, $handler);

// if handler throws a HttpException/Exception it will be turned into a psr-7 response