studiow/http-exceptions
最新稳定版本:v1.0.3
Composer 安装命令:
composer require studiow/http-exceptions
包简介
HTTP exceptions
README 文档
README
A helper package for throwing HTTP Exceptions (4xx - 5xx)
Installation
The easiest way to install this package is using composer:
composer require studiow/http-exceptions
Throwing exceptions
The package provides dedicated Exceptions for each of the 4xx and 5xx error status codes. You throw them like you would throw any other exception:
if (! file_exists($my_file)){ throw new \Studiow\Http\Exceptions\ClientError\NotFoundException(); }
Outputting to Json
All of the exceptions have a toJsonResponse method. This method expects a PSR-7 ResponseInterface object and will return a a PSR-7 ResponseInterface object with the appropriate headers, status code and reason phrase set.
$exception = new \Studiow\Http\Exceptions\ClientError\NotFoundException(); /* convert the exception to a ResponseInterfaceObject */ $response = $exception->toJsonResponse(new \GuzzleHttp\Psr7\Response());
Exception overview
Client Error (4xx)
| Status Code | Reason Phrase | Class name |
|---|---|---|
| 400 | Bad Request | \Studiow\Http\Exceptions\ClientError\BadRequestException |
| 401 | Unauthorized | \Studiow\Http\Exceptions\ClientError\UnauthorizedException |
| 402 | Payment Required | \Studiow\Http\Exceptions\ClientError\PaymentRequiredException |
| 403 | Forbidden | \Studiow\Http\Exceptions\ClientError\ForbiddenException |
| 404 | Not Found | \Studiow\Http\Exceptions\ClientError\NotFoundException |
| 405 | Method Not Allowed | \Studiow\Http\Exceptions\ClientError\MethodNotAllowedException |
| 406 | Not Acceptable | \Studiow\Http\Exceptions\ClientError\NotAcceptableException |
| 407 | Proxy Authentication Required | \Studiow\Http\Exceptions\ClientError\ProxyAuthenticationRequiredException |
| 408 | Request Timeout | \Studiow\Http\Exceptions\ClientError\RequestTimeoutException |
| 409 | Conflict | \Studiow\Http\Exceptions\ClientError\ConflictException |
| 410 | Gone | \Studiow\Http\Exceptions\ClientError\GoneException |
| 411 | Length Required | \Studiow\Http\Exceptions\ClientError\LengthRequiredException |
| 412 | Precondition Failed | \Studiow\Http\Exceptions\ClientError\PreconditionFailedException |
| 413 | Payload Too Large | \Studiow\Http\Exceptions\ClientError\PayloadTooLargeException |
| 414 | URI Too Long | \Studiow\Http\Exceptions\ClientError\URITooLongException |
| 415 | Unsupported Media Type | \Studiow\Http\Exceptions\ClientError\UnsupportedMediaTypeException |
| 416 | Range Not Satisfiable | \Studiow\Http\Exceptions\ClientError\RangeNotSatisfiableException |
| 417 | Expectation Failed | \Studiow\Http\Exceptions\ClientError\ExpectationFailedException |
| 418 | I'm a Teapot | \Studiow\Http\Exceptions\ClientError\ImaTeapotException |
| 421 | Misdirected Request | \Studiow\Http\Exceptions\ClientError\MisdirectedRequestException |
| 422 | Unprocessable Entity | \Studiow\Http\Exceptions\ClientError\UnprocessableEntityException |
| 423 | Locked | \Studiow\Http\Exceptions\ClientError\LockedException |
| 424 | Failed Dependency | \Studiow\Http\Exceptions\ClientError\FailedDependencyException |
| 425 | Too Early | \Studiow\Http\Exceptions\ClientError\TooEarlyException |
| 426 | Upgrade Required | \Studiow\Http\Exceptions\ClientError\UpgradeRequiredException |
| 428 | Precondition Required | \Studiow\Http\Exceptions\ClientError\PreconditionRequiredException |
| 429 | Too Many Requests | \Studiow\Http\Exceptions\ClientError\TooManyRequestsException |
| 431 | Request Header Fields Too Large | \Studiow\Http\Exceptions\ClientError\RequestHeaderFieldsTooLargeException |
| 451 | Unavailable For Legal Reasons | \Studiow\Http\Exceptions\ClientError\UnavailableForLegalReasonsException |
Server Error (5xx)
| Status Code | Reason Phrase | Class name |
|---|---|---|
| 501 | Not Implemented | \Studiow\Http\Exceptions\ServerError\NotImplementedException |
| 502 | Bad Gateway | \Studiow\Http\Exceptions\ServerError\BadGatewayException |
| 503 | Service Unavailable | \Studiow\Http\Exceptions\ServerError\ServiceUnavailableException |
| 504 | Gateway Timeout | \Studiow\Http\Exceptions\ServerError\GatewayTimeoutException |
| 505 | HTTP Version Not Supported | \Studiow\Http\Exceptions\ServerError\HTTPVersionNotSupportedException |
| 506 | Variant Also Negotiates | \Studiow\Http\Exceptions\ServerError\VariantAlsoNegotiatesException |
| 507 | Insufficient Storage | \Studiow\Http\Exceptions\ServerError\InsufficientStorageException |
| 508 | Loop Detected | \Studiow\Http\Exceptions\ServerError\LoopDetectedException |
| 510 | Not Extended | \Studiow\Http\Exceptions\ServerError\NotExtendedException |
| 511 | Network Authentication Required | \Studiow\Http\Exceptions\ServerError\NetworkAuthenticationRequiredException |
统计信息
- 总下载量: 2.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-21