idiosyncratic / http-exceptions
PSR HTTP 服务器请求的异常
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-08-29 05:08:45 UTC
README
简介
一个提供 HTTP 请求异常类的库。HTTP 异常需要服务器请求实例来便于高级异常处理器生成适当的响应(例如,在响应中发送正确的内容类型)。
安装
使用 Composer
composer require idiosyncratic/http-exceptions
用法
use Idiosyncratic\Http\Exception\Server\InternalServerError; // $request must be an instance of Psr\Http\Message\ServerRequestInterface; throw new InternalServerError($request);
您也可以像常规异常一样包装之前的异常。
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); }