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

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

wellrested/http-exceptions
==========================

A collection of exceptions that correspond to common HTTP error status codes

v1.0.0(10y ago)02991MITPHPPHP &gt;=5.3.0

Since May 30Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (1)

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

[](#httpexceptions)

`HttpException` 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 `$message` and the status code as the `$code`.

This package provides the following exception classes in the `WellRESTed\HttpExceptions` namespace.

ExceptionCodeMessageHttpException500"Internal Server Error"BadRequestException400"Bad Request"UnauthorizedException401"Unauthorized"ForbiddenException403"Forbidden"NotFoundException404"Not Found"MethodNotAllowedException405"Method Not Allowed"NotAcceptableException406"Not AcceptableConflictException409"Conflict"GoneException410"Gone"LengthRequiredException411"Length Required"PreconditionFailedException412"Precondition Failed"RequestEntityTooLargeException413"Request Entity Too Large"UnsupportedMediaTypeException415"Unsupported Media Type"RequestedRangeNotSatisfiableException416"Requested Range Not Satisfiable"ExpectationFailedException417"Expectation Failed"Basic Usage
-----------

[](#basic-usage)

Throw an exception.

```
throw new \WellRESTed\HttpExceptions\UnauthorizedException();
```

Throw a custom exception, providing a status code.

```
throw new \WellRESTed\HttpExceptions\HttpException(
    "HTTP Version Not Supported", 505);
```

Catch an exception and output an HTML response.

```
try {
    // ...
} catch (\WellRESTed\HttpExceptions\HttpException $e) {
    http_response_code($e->getCode());
    header("Content-type: text/html");
    print "" . $e->getCode()  . " " . $e->getMessage() . "";
}
```

Or, if you're using [WellRESTed](https://github.com/wellrestedphp/wellrested):

```
try {
    // ...
} catch (\WellRESTed\HttpExceptions\HttpException $e) {
    $response = $response
        ->withStatus($e->getCode())
        ->withHeader("Content-type", "text/html")
        ->withBody(new \WellRESTed\Message\Stream(
            "" . $e->getCode()  . " " . $e->getMessage() . ""));
}
```

Install
-------

[](#install)

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

```
{
    "require": {
        "wellrested/http-exceptions": "^1.0"
    }
}
```

Copyright and License
---------------------

[](#copyright-and-license)

Copyright © 2015 by PJ Dietz Licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4007d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/51c270797760b2893b6300c7efa1a4d3ef117771f901debea3954d947201e51e?d=identicon)[pjdietz](/maintainers/pjdietz)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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