PHPackages                             boltics/http-exception - 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. boltics/http-exception

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

boltics/http-exception
======================

An exception that contains http status code

v1.0.5(5y ago)07.2kMITPHPPHP &gt;=7.1

Since Nov 9Pushed 5y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (8)Used By (0)

PHP Exception with http status code
===================================

[](#php-exception-with-http-status-code)

[![Build Status](https://camo.githubusercontent.com/3b3007e23649db3677d829a46e5c685820bad1c0c1b2da06642a9c4078698e1f/68747470733a2f2f7472617669732d63692e6f72672f626f6c746963732f687474702d657863657074696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/boltics/http-exception)[![Coverage Status](https://camo.githubusercontent.com/297e732cfd95b7a6bdc4f7b7c06820a8609fa7b8677e2028b49fa4e19504f88a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f626f6c746963732f687474702d657863657074696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/boltics/http-exception?branch=master)

A exception that extends PHP exception and also contains http status code.

Now you can easily manage your error code and http status code together!

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

[](#installation)

```
composer require boltics\http-exception

```

Declaration
-----------

[](#declaration)

```
use Boltics\HttpException\Exception;
use Symfony\Component\HttpFoundation\Response;
```

Usage
-----

[](#usage)

```
$errorInfo = [
    'message' => 'Hola',
    'errorCode' => 1234,
    'httpCode' => Response::HTTP_BAD_REQUEST
];

throw new Exception($errorInfo);

// For Laravel Response
// You can use one exception to manage both error code and http code

class CustomizedException extends Exception
{
    const FIRST_ERROR = [
        'message' => 'Hola',
        'errorCode' => 1234,
        'httpCode' => Response::HTTP_BAD_REQUEST
    ];
}

try {
    // do something
    throw new CustomizedException(CustomizedException::FIRST_ERROR);
} catch (CustomizedException $e) {
    return $reponse()->json($data, $e->getHttpCode())
}
```

Documentation
-------------

[](#documentation)

- `__construct()` The constructor checks that the value exist in the enum
- `getHttpCode()` Returns http code
- `setHttpCode()` Set http code
- `getErrorCode()` Another approach to get exception code
- `setAdditionalData()` Set additional data
- `getAdditionalData()` Get additional data
- `appendAdditionalData()` Append data to the additional data

Static methods:

- `isValidHttpCode()` method Returns boolean that http code is valid (in the supported list)
- `sanitizeException()` method Returns valid exception info for \_\_construct()

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 96.7% 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 ~204 days

Recently: every ~255 days

Total

6

Last Release

2082d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.0

v1.0.3PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b7421944a91a6164c5633050ad39ddb2042f664da22c2b988e046854007bd7f?d=identicon)[TeamBoltics](/maintainers/TeamBoltics)

---

Top Contributors

[![MAJA-Lin](https://avatars.githubusercontent.com/u/11385444?v=4)](https://github.com/MAJA-Lin "MAJA-Lin (29 commits)")[![alanz-evo](https://avatars.githubusercontent.com/u/45761833?v=4)](https://github.com/alanz-evo "alanz-evo (1 commits)")

---

Tags

typeexceptionhttp-status-codehttp codehttpcode

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/boltics-http-exception/health.svg)

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

###  Alternatives

[api-platform/http-cache

API Platform HttpCache component

223.2M7](/packages/api-platform-http-cache)[airbrake/phpbrake

Airbrake exception and error notifier for PHP

492.0M25](/packages/airbrake-phpbrake)[ph-7/just-http-status-codes

Just all HTTP status codes

1447.7k4](/packages/ph-7-just-http-status-codes)[middlewares/error-handler

Middleware to handle http errors

14104.2k13](/packages/middlewares-error-handler)

PHPackages © 2026

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