PHPackages                             loadsys/cakephp-serializers-errors - 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. [API Development](/categories/api)
4. /
5. loadsys/cakephp-serializers-errors

ActiveCakephp-plugin[API Development](/categories/api)

loadsys/cakephp-serializers-errors
==================================

Used to serialize CakePHP Errors and Exceptions, primarily as HTML, JSON or JSON API.

1.0.2(10y ago)02.1k[3 issues](https://github.com/loadsys/CakePHP-Serializers-Errors/issues)1MITPHPPHP &gt;=5.4.0

Since May 5Pushed 10y ago8 watchersCompare

[ Source](https://github.com/loadsys/CakePHP-Serializers-Errors)[ Packagist](https://packagist.org/packages/loadsys/cakephp-serializers-errors)[ Docs](https://github.com/loadsys/CakePHP-Serializers-Errors)[ RSS](/packages/loadsys-cakephp-serializers-errors/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (6)Used By (1)

CakePHP SerializersErrors
=========================

[](#cakephp-serializerserrors)

[![Latest Version](https://camo.githubusercontent.com/04d0fe9c44f5483c61f9cb55f44ad353d1e72bddba2e3841f587aa6283318139/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6c6f61647379732f43616b655048502d53657269616c697a6572732d4572726f72732e7376673f7374796c653d666c61742d737175617265)](https://github.com/loadsys/CakePHP-Serializers-Errors/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6e02e772a8c185759096bc08ef6b1e20284c0f8b12bcc1f99f40d6ac13246ccc/68747470733a2f2f7472617669732d63692e6f72672f6c6f61647379732f43616b655048502d53657269616c697a6572732d4572726f72732e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.org/loadsys/CakePHP-Serializers-Errors)[![Coverage Status](https://camo.githubusercontent.com/c4342eace65a3b75be458c34f5e31770d5fb445279aa64e2d2f8606010c24f25/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6c6f61647379732f43616b655048502d53657269616c697a6572732d4572726f72732f62616467652e737667)](https://coveralls.io/r/loadsys/CakePHP-Serializers-Errors)[![Total Downloads](https://camo.githubusercontent.com/bc4134e91a6ff4023a979f15acb7fe1d6a9b5990b8f02437cb4e2f5c260faaaf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f61647379732f63616b657068702d73657269616c697a6572732d6572726f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loadsys/cakephp-serializers-errors)

Used to serialize CakePHP Errors and Exceptions, primarily as HTML, JSON or JSON API.

Adds two new Exception Classes to extend from to get [JSON API](http://jsonapi.org/format/#errors) formatted error messages.

Requirements
------------

[](#requirements)

- CakePHP 2.3+
- PHP 5.4+

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

[](#installation)

### Composer

[](#composer)

```
$ composer require loadsys/cakephp-serializers-errors:~1.0
```

Usage
-----

[](#usage)

- Add this plugin to your application by adding this line to your bootstrap.php

```
CakePlugin::load('SerializersErrors', array('bootstrap' => true));
```

- Update your `core.php` to use the plugin's ExceptionRenderer in place of the core's

```
Configure::write('Exception', array(
	'handler' => 'ErrorHandler::handleException',
	'renderer' => 'SerializersErrors.SerializerExceptionRenderer',
	'log' => true,
));
```

- Once this is done Exceptions are rendered as possible, [JSON API errors](http://jsonapi.org/format/#errors), JSON formated errors or standard HTML responses, differing on the request `Accepts` Header.
- So if you use:

- `Accepts: application/vnd.api+json` JSON API Errors are returned
- `Accepts: application/json` JSON Errors are returned
- `Accepts: */*` Normal CakePHP HTML Style Errors are returned

- If you build custom Exceptions that extend `BaseSerializerException` you get Exceptions that enable the full feature set of [JSON API errors](http://jsonapi.org/format/#errors)in addition to be rendering in the pattern described above.

Sample Responses
----------------

[](#sample-responses)

Here are some sample response for the different Exception classes.

### BaseSerializerException

[](#baseserializerexception)

#### Accepts: application/vnd.api+json

[](#accepts-applicationvndapijson)

Matches the format expected in [JSON API](http://jsonapi.org/format/#errors)

```
throw new BaseSerializerException("This is a message.", "Something failed", 400, "Custom ID For Error", "http://docs.domain.com/api/v1/custom-id-for-error", array(), array())
```

```
{
	"errors": [
		{
			"id": "Custom ID For Error",
			"href": "http://docs.domain.com/api/v1/custom-id-for-error",
			"status": "401",
			"code": "401",
			"title": "Title of the Error",
			"detail": "More Detailed information",
			"links": [],
			"paths": []
		}
	]
}
```

#### Accepts: application/json

[](#accepts-applicationjson)

```
throw new BaseSerializerException("This is a message.", "Something failed", 400, "Custom ID For Error", "http://docs.domain.com/api/v1/custom-id-for-error", array(), array())
```

```
{
	"id": "Custom ID For Error",
	"href": "http://docs.domain.com/api/v1/custom-id-for-error",
	"status": "400",
	"code": "400",
	"detail": "Something failed",
	"links": [],
	"paths": []
}
```

### ValidationBaseSerializerException

[](#validationbaseserializerexception)

#### Accepts: application/vnd.api+json

[](#accepts-applicationvndapijson-1)

Matches the format expected in [JSON API](http://jsonapi.org/format/#errors)

```
throw new ValidationBaseSerializerException("This is a message.", $this->ModelName->invalidFields(), 422, "Custom ID For Error", "http://docs.domain.com/api/v1/custom-id-for-error", array(), array())
```

```
{
	"errors": {
		"id": "Custom ID For Error",
		"href": "http://docs.domain.com/api/v1/custom-id-for-error",
		"status": "400",
		"code": "400",
		"title": "This is a message.",
		"detail": {
			"username": [
				"Username can not be empty",
				"Username can only be alphanumeric characters"
			],
			"first_name": [
				"First Name must be longer than 4 characters"
			]
		},
		"links": [],
		"paths": []
	}
}
```

#### Accepts: application/json

[](#accepts-applicationjson-1)

Matches the format expected in [Ember.js DS.Errors Class](http://emberjs.com/api/data/classes/DS.Errors.html)

```
$invalidFields = $this->ModelName->invalidFields();
throw new ValidationBaseSerializerException("This is a message.", $invalidFields, 422, "Custom ID For Error", "http://docs.domain.com/api/v1/custom-id-for-error", array(), array())
```

```
{
	"errors": {
		"name": [
			"Name must not be empty.",
			"Name must be only alphanumeric characters"
		],
		"status": [
			"Status? must be true or false."
		],
		"SubModel": [
			{
				"options": [
					"Options must take the form `first|second|third` and `formula` must be empty."
				]
			}
		]
	}
}
```

Contributing
------------

[](#contributing)

### Reporting Issues

[](#reporting-issues)

Please use [GitHub Isuses](https://github.com/loadsys/CakePHP-Serializers-Errors/issues) for listing any known defects or issues.

### Development

[](#development)

When developing this plugin, please fork and issue a PR for any new development.

The Complete Test Suite for the plugin can be run via this command:

`./lib/Cake/Console/cake test SerializersErrors AllSerializersErrors`

License
-------

[](#license)

[MIT](https://github.com/loadsys/CakePHP-Serializers-Errors/blob/master/LICENSE.md)

Copyright
---------

[](#copyright)

[Loadsys Web Strategies](http://www.loadsys.com) 2015

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 98% 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 ~106 days

Total

4

Last Release

3711d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58c6913a72757502a801ebc71f995eb1c4f7a53a7de7314a20b9a1f1d6131b60?d=identicon)[jtyost2](/maintainers/jtyost2)

![](https://www.gravatar.com/avatar/2380c6ad9546e6c8ce5c5b641f5a4bce0c4d3e7f3a377dc287936dff50cc3064?d=identicon)[ricog](/maintainers/ricog)

---

Top Contributors

[![justinyost](https://avatars.githubusercontent.com/u/85320?v=4)](https://github.com/justinyost "justinyost (48 commits)")[![chronon](https://avatars.githubusercontent.com/u/57735?v=4)](https://github.com/chronon "chronon (1 commits)")

---

Tags

jsonapicakephpexceptionsserializerscakephp-plugin

### Embed Badge

![Health badge](/badges/loadsys-cakephp-serializers-errors/health.svg)

```
[![Health](https://phpackages.com/badges/loadsys-cakephp-serializers-errors/health.svg)](https://phpackages.com/packages/loadsys-cakephp-serializers-errors)
```

###  Alternatives

[sfelix-martins/json-exception-handler

Adds more power to Laravel Exceptions Handler to treat json responses

1764.6k](/packages/sfelix-martins-json-exception-handler)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.0k](/packages/nilportugues-jsonapi-bundle)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.6M3](/packages/cloudcreativity-json-api-testing)[nekojira/wp-api-menus

Extends WordPress WP API with menu routes.

1401.5k](/packages/nekojira-wp-api-menus)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)[a2design-company/mandrill-cakephp-plugin

Mandrill CakePHP plugin

193.2k](/packages/a2design-company-mandrill-cakephp-plugin)

PHPackages © 2026

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