idiosyncratic / http-exceptions
Exceptions for PSR HTTP Server Requests
0.9.1
2019-11-29 21:50 UTC
Requires
- php: >=7.3
- psr/http-message: ^1.0
Requires (Dev)
- idiosyncratic/devtools: ^0.2
This package is auto-updated.
Last update: 2024-11-29 05:51:20 UTC
README
Introduction
A library providing Exception classes for HTTP Requests. HTTP Exceptions require the server request instance to facilitate advanced exception handlers to generate appropriate responses (for example, sending the correct content type in the response).
Installation
Use Composer:
composer require idiosyncratic/http-exceptions
Usage
use Idiosyncratic\Http\Exception\Server\InternalServerError; // $request must be an instance of Psr\Http\Message\ServerRequestInterface; throw new InternalServerError($request);
You may also wrap a previous exception, just as with a regular Exception:
use Idiosyncratic\Http\Exception\Server\InternalServerError; try { throw new \Exception('Something went wrong'); } catch (\Throwable $throwable) { // $request must be an instance of Psr\Http\Message\ServerRequestInterface; throw new InternalServerError($request, $throwable); }