PHPackages                             acelaya/ze-content-based-error-handler - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. acelaya/ze-content-based-error-handler

AbandonedArchivedLibrary[Logging &amp; Monitoring](/categories/logging)

acelaya/ze-content-based-error-handler
======================================

A Zend Expressive error handler which allows to implement different strategies based on the accepted content-types

v3.0.0(6y ago)1212.8k—0%1[1 issues](https://github.com/acelaya/ze-content-based-error-handler/issues)MITPHPPHP ^7.2

Since Aug 12Pushed 6y ago2 watchersCompare

[ Source](https://github.com/acelaya/ze-content-based-error-handler)[ Packagist](https://packagist.org/packages/acelaya/ze-content-based-error-handler)[ RSS](/packages/acelaya-ze-content-based-error-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (8)Used By (0)

⚠️ This project is deprecated ⚠️
================================

[](#warning-this-project-is-deprecated-warning)

If you need to return different kinds of responses based on the request accepted content type, its easier to pipe different middlewares for every type, and let the next handler to be called if one is not able to generate the response.

Zend Expressive ContentBasedErrorResponseGenerator
==================================================

[](#zend-expressive-contentbasederrorresponsegenerator)

[![Build Status](https://camo.githubusercontent.com/f4acd9791b62ea1bcc2d4c4a18e276c30541a858bae301af04106d9be337dc61/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6163656c6179612f7a652d636f6e74656e742d62617365642d6572726f722d68616e646c65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/acelaya/ze-content-based-error-handler)[![Code Coverage](https://camo.githubusercontent.com/994f158333c9dd5ea85b1ebc4a56a8cb11d9cb6d48908890b609c5e3f91347ca/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6163656c6179612f7a652d636f6e74656e742d62617365642d6572726f722d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/679e3ffea047e661e5e5f098de0a665151cd2212525742f4c75f8ed3bb870f74/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6163656c6179612f7a652d636f6e74656e742d62617365642d6572726f722d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/1182ced1c2eaa0ba7211a31e3e3d2c16d8637a5cd21f4b081a407061797f70be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6163656c6179612f7a652d636f6e74656e742d62617365642d6572726f722d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)[![Total Downloads](https://camo.githubusercontent.com/dc2dc4dd7f684fa49903fb09c079f899f2dadc01eff7a31a68eb056e549414dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6163656c6179612f7a652d636f6e74656e742d62617365642d6572726f722d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)[![License](https://camo.githubusercontent.com/c4f82226666ab9b0ba7909265d84333204d28c5ca277068fec89c803087a7864/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6163656c6179612f7a652d636f6e74656e742d62617365642d6572726f722d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/acelaya/ze-content-based-error-handler/blob/master/LICENSE)[![Paypal Donate](https://camo.githubusercontent.com/d747bb27455dd0b8a72005e7c31ded7c8a6e28231f31578024833a9267d0f0c4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d70617970616c2d626c75652e7376673f7374796c653d666c61742d737175617265266c6f676f3d70617970616c26636f6c6f72413d636363636363)](https://acel.me/donate)

A Zend Expressive error response generator which allows to implement different strategies to render error responses based on the accepted content-types.

### Context

[](#context)

This package was created following this article .

On it, I demonstrate how to implement an strategy-based system which generates different error responses by taking into account the request's `Accept` header.

After writing the article I decided to create this package, so that everybody can install and use the provided solution in their own projects.

The package has then evolved to support expressive 2, which completely drops the concept of error handlers. Instead, from v2, this provides error response generators.

### Installation

[](#installation)

Use composer to install this package

```
composer require acelaya/ze-content-based-error-handler

```

### Usage

[](#usage)

This package includes an error response generator, the `Acelaya\ExpressiveErrorHandler\ErrorHandler\ContentBasedErrorResponseGenerator`, that can be used to replace default Zend Expressive implementations.

It composes a plugin manager that fetches a concrete error response generator at runtime, based on the Request's `Accept` header. Thus, you can use the Expressive's `ErrorResponseGenerator` to dispatch **text/html** request errors, Stratiglity's `ErrorResponseGenerator` for **text/plain** errors, etc.

You can also provide your own implementations for other content-types, like **application/json** or **text/xml**. The ContentBasedErrorResponseGenerator will automatically use the proper implementation.

### Provided configuration

[](#provided-configuration)

To get things easily working, a `ConfigProvider` is included, which automatically registers all the dependencies in the service container (including the `Zend\Expressive\Middleware\ErrorResponseGenerator` service).

It also preregisters error handlers for html and plain text requests (The `Zend\Expressive\Middleware\ErrorResponseGenerator` and the `Zend\Stratigility\Middleware\ErrorResponseGenerator` as mentioned before).

```
