PHPackages                             pavelsterba/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. pavelsterba/http-exceptions

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

pavelsterba/http-exceptions
===========================

HTTP status code exceptions for PHP.

v2.0(3y ago)9107.5k—1.6%1MITPHPPHP &gt;=7.4

Since Sep 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/pavelsterba/http-exceptions)[ Packagist](https://packagist.org/packages/pavelsterba/http-exceptions)[ Docs](https://github.com/pavelsterba/http-exceptions)[ RSS](/packages/pavelsterba-http-exceptions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

HTTP Exceptions
===============

[](#http-exceptions)

If you are creating API, [SPL Exceptions](http://php.net/manual/en/spl.exceptions.php) are sometimes not the best choice to describe your problem. That is where **HTTP Exceptions** can be helpful.

Requested data not found? Unauthorized request? XML instead of JSON received? Throw relevant exception!

Installation
------------

[](#installation)

Just add it as dependency to your project:

```
composer require pavelsterba/http-exceptions

```

Usage
-----

[](#usage)

All exceptions can be thrown without any additional information - message and code are predefined.

```
try {
    throw new HttpException\ServerError\InternalServerErrorException();
} catch (HttpException\HttpException $e) {
    echo $e->getMessage(); // 500 Internal Server Error
    echo $e->getCode(); // 500
}
```

To get customized instance of exception, you can pass parameters to exception as usual or use static function `get()`, where you have to specify only message and previous exception:

```
use HttpException\ServerError\InternalServerErrorException;

try {
    // ...
} catch (Exception $ex) {
    throw InternalServerErrorException::get("Server down, sorry.", $ex);
}
```

Structure
---------

[](#structure)

Your API can be fully exception driven since all HTTP statuses from [RFC 9110](https://httpwg.org/specs/rfc9110.html) are implemented as separated exceptions with following hierarchy:

```
Exception
└─ HttpException\HttpException
   ├─ HttpException\InformationalException
   │  ├─ HttpException\Informational\ContinueException
   │  ├─ HttpException\Informational\SwitchingProtocolsException
   │  ├─ HttpException\Informational\ProcessingException
   │  └─ HttpException\Informational\EarlyHintsException
   ├─ HttpException\SuccessfulException
   │  ├─ HttpException\Successful\OKException
   │  ├─ HttpException\Successful\CreatedException
   │  ├─ HttpException\Successful\AcceptedException
   │  ├─ HttpException\Successful\NonAuthoritativeInformationException
   │  ├─ HttpException\Successful\NoContentException
   │  ├─ HttpException\Successful\ResetContentException
   │  ├─ HttpException\Successful\PartialContentException
   │  ├─ HttpException\Successful\MultiStatusException
   │  ├─ HttpException\Successful\AlreadyReportedException
   │  └─ HttpException\Successful\IMUsedException
   ├─ HttpException\RedirectionException
   │  ├─ HttpException\Redirection\MultipleChoicesException
   │  ├─ HttpException\Redirection\MovedPermanentlyException
   │  ├─ HttpException\Redirection\FoundException
   │  ├─ HttpException\Redirection\SeeOtherException
   │  ├─ HttpException\Redirection\NotModifiedException
   │  ├─ HttpException\Redirection\UseProxyException
   │  ├─ HttpException\Redirection\TemporaryRedirectException
   │  └─ HttpException\Redirection\PermanentRedirectException
   ├─ HttpException\ClientErrorException
   │  ├─ HttpException\ClientError\BadRequestException
   │  ├─ HttpException\ClientError\UnauthorizedException
   │  ├─ HttpException\ClientError\PaymentRequiredException
   │  ├─ HttpException\ClientError\ForbiddenException
   │  ├─ HttpException\ClientError\NotFoundException
   │  ├─ HttpException\ClientError\MethodNotAllowedException
   │  ├─ HttpException\ClientError\NotAcceptableException
   │  ├─ HttpException\ClientError\ProxyAuthenticationRequiredException
   │  ├─ HttpException\ClientError\RequestTimeoutException
   │  ├─ HttpException\ClientError\ConflictException
   │  ├─ HttpException\ClientError\GoneException
   │  ├─ HttpException\ClientError\LengthRequiredException
   │  ├─ HttpException\ClientError\PreconditionFailedException
   │  ├─ HttpException\ClientError\PayloadTooLargeException
   │  ├─ HttpException\ClientError\URITooLongException
   │  ├─ HttpException\ClientError\UnsupportedMediaTypeException
   │  ├─ HttpException\ClientError\RangeNotSatisfiableException
   │  ├─ HttpException\ClientError\ExpectationFailedException
   │  ├─ HttpException\ClientError\IMaTeapotException
   │  ├─ HttpException\ClientError\MisdirectedRequestException
   │  ├─ HttpException\ClientError\UnprocessableEntityException
   │  ├─ HttpException\ClientError\LockedException
   │  ├─ HttpException\ClientError\FailedDependencyException
   │  ├─ HttpException\ClientError\TooEarlyException
   │  ├─ HttpException\ClientError\UpgradeRequiredException
   │  ├─ HttpException\ClientError\PreconditionRequiredException
   │  ├─ HttpException\ClientError\TooManyRequestsException
   │  ├─ HttpException\ClientError\RequestHeaderFieldsTooLargeException
   │  └─ HttpException\ClientError\UnavailableForLegalReasonsException
   └─ HttpException\ServerErrorException
      ├─ HttpException\ServerError\InternalServerErrorException
      ├─ HttpException\ServerError\NotImplementedException
      ├─ HttpException\ServerError\BadGatewayException
      ├─ HttpException\ServerError\ServiceUnavailableException
      ├─ HttpException\ServerError\GatewayTimeoutException
      ├─ HttpException\ServerError\HTTPVersionNotSupportedException
      ├─ HttpException\ServerError\VariantAlsoNegotiatesException
      ├─ HttpException\ServerError\InsufficientStorageException
      ├─ HttpException\ServerError\LoopDetectedException
      ├─ HttpException\ServerError\NotExtendedException
      └─ HttpException\ServerError\NetworkAuthenticationRequiredException

```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

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 ~1295 days

Total

3

Last Release

1292d ago

Major Versions

v1.1 → v2.02022-11-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/61f7240335c7188c102d371409cf95d12914b36c3742162bdac1857081c1f681?d=identicon)[pavelsterba](/maintainers/pavelsterba)

---

Top Contributors

[![pavelsterba](https://avatars.githubusercontent.com/u/6181620?v=4)](https://github.com/pavelsterba "pavelsterba (2 commits)")

---

Tags

httpphpapiexceptions

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ciareis/bypass

Bypass for PHP provides a quick way to create a custom instead of an actual HTTP server to return prebaked responses to client requests. This is most useful in tests, when you want to create a mock HTTP server and test how your HTTP client handles different types of responses from the server.

11813.5k6](/packages/ciareis-bypass)

PHPackages © 2026

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