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(11y ago)02991MITPHPPHP &gt;=5.3.0

Since May 30Pushed 11y 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 today

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 47% 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

4053d 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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M92](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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