PHPackages                             chiron/http-exceptions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. chiron/http-exceptions

ActiveLibrary[HTTP &amp; Networking](/categories/http)

chiron/http-exceptions
======================

Exception classes for Http Exception.

2.03(5y ago)12.7k[1 issues](https://github.com/ncou/Chiron-HttpExceptions/issues)5MITPHPPHP &gt;=7.0

Since Sep 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ncou/Chiron-HttpExceptions)[ Packagist](https://packagist.org/packages/chiron/http-exceptions)[ Docs](https://github.com/ncou/Chiron-HttpExceptions)[ GitHub Sponsors](https://github.com/ncou)[ RSS](/packages/chiron-http-exceptions/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (5)

[![Build Status](https://camo.githubusercontent.com/99407d6bf7c756a3d715d925d81a54ed942973509751ecc7fe8ee0c516795c9b/68747470733a2f2f7472617669732d63692e6f72672f6e636f752f436869726f6e2d48747470457863657074696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ncou/Chiron-HttpExceptions)[![Coverage Status](https://camo.githubusercontent.com/e04df0fbf739584855220a43b4cdfa2f57186cd03feee4eb71ae0eeb1b134f40/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e636f752f436869726f6e2d48747470457863657074696f6e732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ncou/Chiron-HttpExceptions?branch=master)[![CodeCov](https://camo.githubusercontent.com/fc4862382b62bfff04bc3f9b5e4649e559e9bd33c314a7942ae3749a25db6aea/68747470733a2f2f636f6465636f762e696f2f67682f6e636f752f436869726f6e2d48747470457863657074696f6e732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ncou/Chiron-HttpExceptions)

[![Total Downloads](https://camo.githubusercontent.com/ae66edacca9b590feca53fb19faba59653c1d1b49c86fcb23890268516294de3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636869726f6e2f687474702d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/http-exceptions/stats)[![Monthly Downloads](https://camo.githubusercontent.com/7932c7d0cb6d6df1566e939efeb0f7ef42157d3710ee8f6a4f1beb801dbf32a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f636869726f6e2f687474702d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chiron/http-exceptions/stats)

[![StyleCI](https://camo.githubusercontent.com/4c7dffb722b845602150646c8e5324d00c54245e106e07b080f3ff2f39a3d7c9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134373932393636332f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/147929663)[![PHP-Eye](https://camo.githubusercontent.com/f3f88b154838a20d89cd8a6abd123c5b33d2782305bda00862c8131478a4b6b2/68747470733a2f2f7068702d6579652e636f6d2f62616467652f636869726f6e2f687474702d657863657074696f6e732f7465737465642e7376673f7374796c653d666c6174)](https://php-eye.com/package/chiron/http-exceptions)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

HttpExceptions
==============

[](#httpexceptions)

**All HTTP statuses from [RFC 7231](http://tools.ietf.org/html/rfc7231) implemented as separated Exceptions.**

**These Exceptions support a straightforward implementation of the IETF Problem Details for HTTP APIs [RFC 7807](https://tools.ietf.org/html/rfc7807).**

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 :***

ExceptionCodeMessage[BadRequestHttpException](src/Client/BadRequestHttpException.php)400"Bad Request"[UnauthorizedHttpException](src/Client/UnauthorizedHttpException.php)401"Unauthorized"[PaymentRequiredHttpException](src/Client/PaymentRequiredHttpException.php)402"Payment Required"[ForbiddenHttpException](src/Client/ForbiddenHttpException.php)403"Forbidden"[NotFoundHttpException](src/Client/NotFoundHttpException.php)404"Not Found"[MethodNotAllowedHttpException](src/Client/MethodNotAllowedHttpException.php)405"Method Not Allowed"[NotAcceptableHttpException](src/Client/NotAcceptableHttpException.php)406"Not Acceptable"[ProxyAuthenticationRequiredHttpException](src/Client/ProxyAuthenticationRequiredHttpException.php)407"Proxy Authentication Required"[RequestTimeoutHttpException](src/Client/RequestTimeoutHttpException.php)408"Request Timeout"[ConflictHttpException](src/Client/ConflictHttpException.php)409"Conflict"[GoneHttpException](src/Client/GoneHttpException.php)410"Gone"[LengthRequiredHttpException](src/Client/LengthRequiredHttpException.php)411"Length Required"[PreconditionFailedHttpException](src/Client/PreconditionFailedHttpException.php)412"Precondition Failed"[PayloadTooLargeHttpException](src/Client/PayloadTooLargeHttpException.php)413"Payload Too Large"[UriTooLongHttpException](src/Client/UriTooLongHttpException.php)414"URI Too Long"[UnsupportedMediaTypeHttpException](src/Client/UnsupportedMediaTypeHttpException.php)415"Unsupported Media Type"[RangeNotSatisfiableHttpException](src/Client/RangeNotSatisfiableHttpException.php)416"Range Not Satisfiable"[ExpectationFailedHttpException](src/Client/ExpectationFailedHttpException.php)417"Expectation Failed"[MisdirectedRequestHttpException](src/Client/MisdirectedRequestHttpException.php)421"Misdirected Request"[UnprocessableEntityHttpException](src/Client/UnprocessableEntityHttpException.php)422"Unprocessable Entity"[LockedHttpException](src/Client/LockedHttpException.php)423"Locked"[FailedDependencyHttpException](src/Client/FailedDependencyHttpException.php)424"Failed Dependency"[TooEarlyHttpException](src/Client/TooEarlyHttpException.php)425"Too Early"[UpgradeRequiredHttpException](src/Client/UpgradeRequiredHttpException.php)426"Upgrade Required"[PreconditionRequiredHttpException](src/Client/PreconditionRequiredHttpException.php)428"Precondition Required"[TooManyRequestsHttpException](src/Client/TooManyRequestsHttpException.php)429"Too Many Requests"[RequestHeaderFieldsTooLargeHttpException](src/Client/RequestHeaderFieldsTooLargeHttpException.php)431"Request Header Fields Too Large"[UnavailableForLegalReasonsHttpException](src/Client/UnavailableForLegalReasonsHttpException.php)451"Unavailable For Legal Reasons"***Server errors :***

ExceptionCodeMessage[InternalServerErrorHttpException](src/Server/InternalServerErrorHttpException.php)500"Internal Server Error"[NotImplementedHttpException](src/Server/NotImplementedHttpException.php)501"'Not Implemented"[BadGatewayHttpException](src/Server/BadGatewayHttpException.php)502"Bad Gateway"[ServiceUnavailableHttpException](src/Server/ServiceUnavailableHttpException.php)503"Service Unavailable"[GatewayTimeoutHttpException](src/Server/GatewayTimeoutHttpException.php)504"Gateway Timeout"[HttpVersionNotSupportedHttpException](src/Server/HttpVersionNotSupportedHttpException.php)505"HTTP Version Not Supported"[VariantAlsoNegotiatesHttpException](src/Server/VariantAlsoNegotiatesHttpException.php)506"Variant Also Negotiates"[InsufficientStorageHttpException](src/Server/InsufficientStorageHttpException.php)507"Insufficient Storage"[LoopDetectedHttpException](src/Server/LoopDetectedHttpException.php)508"Loop Detected"[NotExtendedHttpException](src/Server/NotExtendedHttpException.php)510"Not Extended"[NetworkAuthenticationRequiredHttpException](src/Server/NetworkAuthenticationRequiredHttpException.php)511"Network Authentication Required"*[References for HTTP status code](https://www.iana.org/assignments/http-status-codes/http-status-codes.xml)*

Basic Usage
-----------

[](#basic-usage)

Throw an exception.

```
throw new \Chiron\Http\Exception\Client\BadRequestHttpException();
```

Throw an exception with a custom message.

```
$e = new \Chiron\Http\Exception\Client\BadRequestHttpException("Invalid syntax !");
throw $e->setHeaders(['X-Custom-Header' => 'foobar']);
```

Catch an exception and output an HTML response.

```
try {
    // ...
} catch (\Chiron\Http\Exception\HttpException $e) {
    http_response_code($e->getStatusCode());
    header("Content-type: text/html");
    print "" . $e->getMessage() . "";
}
```

Or, if you're using PSR7 response :

```
try {
    // ...
} catch (\Chiron\Http\Exception\HttpExceptionInterface $e) {
    $response = $response
        ->withStatus($e->getStatusCode())
        ->withHeader("Content-type", "text/html")
        ->getBody()->write("" . $e->getMessage() . "");
}
```

Api Problem
-----------

[](#api-problem)

The following properties are available to use it for API Problem [RFC 7807](https://tools.ietf.org/html/rfc7807#page-5).

```
$e = new \Chiron\Http\Exception\Client\ForbiddenHttpException();

$e->setTitle('You do not have enough credit.');
$e->setDetail('Your current balance is 30, but that costs 50.');
$e->setType('https://example.com/probs/out-of-credit');
$e->setIntance('https://example.net/account/12345/msgs/abc');
$e->setAdditionalData(['balance' => 30, 'accounts' => ['https://example.net/account/12345', 'https://example.net/account/67890']]);

throw $e;
```

And output the API Problem response like this :

```
try {
    // ...
} catch (\Chiron\Http\Exception\HttpException $e) {
    http_response_code($e->getStatusCode());
    header("Content-type: application/problem+json");
    print json_encode($e);
}
```

For XML output you can use the function `$e->toArray()` and serialize the data.

Install
-------

[](#install)

Add `Chiron/http-exceptions` to your composer.json

```
{
    "require": {
        "chiron/http-exceptions": "^2.0"
    }
}
```

License
-------

[](#license)

Licensed under the [MIT license](LICENSE.md)

Suggestions
-----------

[](#suggestions)

Tips : [Usage Suggestion](USAGE_SUGGESTION.md)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~147 days

Recently: every ~265 days

Total

9

Last Release

1630d ago

Major Versions

1.3 → 2.02018-12-31

PHP version history (2 changes)1.0PHP &gt;=7.0

2.1.0PHP ^8.0|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16743322?v=4)[ncou](/maintainers/ncou)[@ncou](https://github.com/ncou)

---

Top Contributors

[![ncou](https://avatars.githubusercontent.com/u/16743322?v=4)](https://github.com/ncou "ncou (50 commits)")

---

Tags

httpapiexceptionsrfc7807rfc7231httpExceptionproblem

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chiron-http-exceptions/health.svg)

```
[![Health](https://phpackages.com/badges/chiron-http-exceptions/health.svg)](https://phpackages.com/packages/chiron-http-exceptions)
```

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[quickbooks/payments-sdk

The Official PHP SDK for QuickBooks Online Payments API

2758.2k2](/packages/quickbooks-payments-sdk)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
