Download the PHP package chiron/http-exceptions without Composer
On this page you can find all versions of the php package chiron/http-exceptions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package http-exceptions
HttpExceptions
All HTTP statuses from RFC 7231 implemented as separated Exceptions.
These Exceptions support a straightforward implementation of the IETF Problem Details for HTTP APIs RFC 7807.
abstract HttpException
class and its subclasses provide exceptions corresponding to HTTP
error status codes. The most common are included, but you can create exceptions
for other status codes by using (or subclassing) HttpException
and providing
the reason phrase as the $title
and the status code as the $statusCode
.
This package provides the following exception classes in the
Chiron\Http\Exception\Client
namespace for 4xx http errors.
And Chiron\Http\Exception\Server
namespace for 5xx http errors.
4xx: Client Error - The request contains bad syntax or cannot be fulfilled 5xx: Server Error - The server failed to fulfill an apparently valid request
Client errors :
Exception | Code | Message |
---|---|---|
BadRequestHttpException | 400 | "Bad Request" |
UnauthorizedHttpException | 401 | "Unauthorized" |
PaymentRequiredHttpException | 402 | "Payment Required" |
ForbiddenHttpException | 403 | "Forbidden" |
NotFoundHttpException | 404 | "Not Found" |
MethodNotAllowedHttpException | 405 | "Method Not Allowed" |
NotAcceptableHttpException | 406 | "Not Acceptable" |
ProxyAuthenticationRequiredHttpException | 407 | "Proxy Authentication Required" |
RequestTimeoutHttpException | 408 | "Request Timeout" |
ConflictHttpException | 409 | "Conflict" |
GoneHttpException | 410 | "Gone" |
LengthRequiredHttpException | 411 | "Length Required" |
PreconditionFailedHttpException | 412 | "Precondition Failed" |
PayloadTooLargeHttpException | 413 | "Payload Too Large" |
UriTooLongHttpException | 414 | "URI Too Long" |
UnsupportedMediaTypeHttpException | 415 | "Unsupported Media Type" |
RangeNotSatisfiableHttpException | 416 | "Range Not Satisfiable" |
ExpectationFailedHttpException | 417 | "Expectation Failed" |
MisdirectedRequestHttpException | 421 | "Misdirected Request" |
UnprocessableEntityHttpException | 422 | "Unprocessable Entity" |
LockedHttpException | 423 | "Locked" |
FailedDependencyHttpException | 424 | "Failed Dependency" |
TooEarlyHttpException | 425 | "Too Early" |
UpgradeRequiredHttpException | 426 | "Upgrade Required" |
PreconditionRequiredHttpException | 428 | "Precondition Required" |
TooManyRequestsHttpException | 429 | "Too Many Requests" |
RequestHeaderFieldsTooLargeHttpException | 431 | "Request Header Fields Too Large" |
UnavailableForLegalReasonsHttpException | 451 | "Unavailable For Legal Reasons" |
Server errors :
Exception | Code | Message |
---|---|---|
InternalServerErrorHttpException | 500 | "Internal Server Error" |
NotImplementedHttpException | 501 | "'Not Implemented" |
BadGatewayHttpException | 502 | "Bad Gateway" |
ServiceUnavailableHttpException | 503 | "Service Unavailable" |
GatewayTimeoutHttpException | 504 | "Gateway Timeout" |
HttpVersionNotSupportedHttpException | 505 | "HTTP Version Not Supported" |
VariantAlsoNegotiatesHttpException | 506 | "Variant Also Negotiates" |
InsufficientStorageHttpException | 507 | "Insufficient Storage" |
LoopDetectedHttpException | 508 | "Loop Detected" |
NotExtendedHttpException | 510 | "Not Extended" |
NetworkAuthenticationRequiredHttpException | 511 | "Network Authentication Required" |
References for HTTP status code
Basic Usage
Throw an exception.
Throw an exception with a custom message.
Catch an exception and output an HTML response.
Or, if you're using PSR7 response :
Api Problem
The following properties are available to use it for API Problem RFC 7807.
And output the API Problem response like this :
For XML output you can use the function $e->toArray()
and serialize the data.
Install
Add Chiron/http-exceptions
to your composer.json
License
Licensed under the MIT license
Suggestions
Tips : Usage Suggestion