PHPackages                             phauthentic/error-response - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. phauthentic/error-response

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

phauthentic/error-response
==========================

0.1.1(2y ago)15[1 issues](https://github.com/Phauthentic/problem-details-response/issues)[1 PRs](https://github.com/Phauthentic/problem-details-response/pulls)MITPHPPHP ^8.1

Since Mar 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Phauthentic/problem-details-response)[ Packagist](https://packagist.org/packages/phauthentic/error-response)[ RSS](/packages/phauthentic-error-response/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (7)Versions (4)Used By (0)

RFC 9457: Problem Details for HTTP APIs
=======================================

[](#rfc-9457-problem-details-for-http-apis)

[![PHP >= 8.1](https://camo.githubusercontent.com/4fa3809f87c8fee607369cc77dc064d826616d28eb87b045ff834d3dbae99119/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d504850266d6573736167653d253545382e3126636f6c6f723d373837434235267374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://camo.githubusercontent.com/4fa3809f87c8fee607369cc77dc064d826616d28eb87b045ff834d3dbae99119/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d504850266d6573736167653d253545382e3126636f6c6f723d373837434235267374796c653d666f722d7468652d6261646765266c6f676f3d706870)[![phpstan Level 8](https://camo.githubusercontent.com/12b6b9438b73c95050b7fc8811f082842fb9d1ec678d3bf802ead8a4b859440c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d7068707374616e266d6573736167653d4c6576656c2532303826636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/12b6b9438b73c95050b7fc8811f082842fb9d1ec678d3bf802ead8a4b859440c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d7068707374616e266d6573736167653d4c6576656c2532303826636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)[![License: MIT](https://camo.githubusercontent.com/d1f48776f80be8eba6920f4e65d7c4b7d1d13bbc6b779d56ca1ecc08181cd2be/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d4c6963656e7365266d6573736167653d4d495426636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/d1f48776f80be8eba6920f4e65d7c4b7d1d13bbc6b779d56ca1ecc08181cd2be/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d4c6963656e7365266d6573736167653d4d495426636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)

This library is an implementation of [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457.html).

---

HTTP status codes cannot always convey enough information about errors to be helpful. While humans using web browsers can often understand an HTML response content, non-human consumers of HTTP APIs have difficulty doing so.

To address that shortcoming, [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457.html) defines simple JSON and XML document formats to describe the specifics of a problem encountered.

For example, consider a response indicating that the client's account doesn't have enough credit. The API's designer might decide to use the 403 Forbidden status code to inform generic HTTP software (such as client libraries, caches, and proxies) of the response's general semantics. API-specific problem details (such as why the server refused the request and the applicable account balance) can be carried in the response content so that the client can act upon them appropriately (for example, triggering a transfer of more credit into the account).

```
HTTP/1.1 403 Forbidden
Content-Type: application/problem+json
Content-Language: en

{
 "type": "https://example.com/probs/out-of-credit",
 "title": "You do not have enough credit.",
 "detail": "Your current balance is 30, but that costs 50.",
 "instance": "/account/12345/msgs/abc",
 "balance": 30,
 "accounts": ["/account/12345",
              "/account/67890"]
}

```

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

[](#installation)

```
composer require phauthentic/error-response
```

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

[](#documentation)

It is recommended to read the [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457.html) at least briefly to understand the RFC and how the actual implementation helps you.

### Middleware

[](#middleware)

The `ErrorResponseMiddleware` is a PSR-15 middleware designed to handle exceptions thrown during the execution of a request and convert them into RFC 9457 conforming error responses.

The middleware takes two argumens:

1. A PSR7 Response Factory implementing `Psr\Http\Message\ResponseFactoryInterface`.
2. An array of exception class names that the middleware should intercept. If an exception is an instance of any of these classes, it will be converted into an error response.

```
$middleware = new ErrorResponseMiddleware(
    new Psr7ResponseFactory(),
    [
        MyCustomException::class,
        OtherExceptionClass::class
    ]
);
```

Use a proper class hierarchy for your exceptions! For example, have a `DatabaseAccessLayerException` from which you derive sub-types instead of declaring hundreds of exception classes and pass them to the middleware.

### Error Responses

[](#error-responses)

Error Responses can be constructed using one of the provided factories or by instantiating the `ErrorResponse` directly.

```
$this->errorResponseFactory->createJsonResponseFromError(
    new ErrorResponse(
        status: 403,
        type: 'https://example.com/probs/out-of-credit',
        title: 'You do not have enough credit.',
        extensions: [
            'balance' => 30,
            'accounts' => [
                "/account/12345",
                "/account/67890"
            ]
        ]
    );
);
```

License
-------

[](#license)

Copyright Florian Krämer

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

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Every ~0 days

Total

2

Last Release

842d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4996022?v=4)[Florian Krämer](/maintainers/floriankraemer)[@floriankraemer](https://github.com/floriankraemer)

---

Top Contributors

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

---

Tags

errorerror-handlingerrorsframework-agnosticphpphp-libraryphp8rfc-9457solid-principles

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phauthentic-error-response/health.svg)

```
[![Health](https://phpackages.com/badges/phauthentic-error-response/health.svg)](https://phpackages.com/packages/phauthentic-error-response)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)

PHPackages © 2026

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