{"id":19571786,"url":"https://github.com/loadsys/cakephp-serializers-errors","last_synced_at":"2025-02-26T10:43:22.175Z","repository":{"id":31242469,"uuid":"34803908","full_name":"loadsys/CakePHP-Serializers-Errors","owner":"loadsys","description":null,"archived":false,"fork":false,"pushed_at":"2016-03-21T02:58:39.000Z","size":42,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":9,"default_branch":"dev","last_synced_at":"2024-03-25T22:28:31.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loadsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-29T16:06:36.000Z","updated_at":"2024-03-25T22:28:31.725Z","dependencies_parsed_at":"2022-09-02T11:51:00.613Z","dependency_job_id":null,"html_url":"https://github.com/loadsys/CakePHP-Serializers-Errors","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Serializers-Errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Serializers-Errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Serializers-Errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsys%2FCakePHP-Serializers-Errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loadsys","download_url":"https://codeload.github.com/loadsys/CakePHP-Serializers-Errors/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240840036,"owners_count":19866164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T06:20:02.792Z","updated_at":"2025-02-26T10:43:22.123Z","avatar_url":"https://github.com/loadsys.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CakePHP SerializersErrors\n\n[![Latest Version](https://img.shields.io/github/release/loadsys/CakePHP-Serializers-Errors.svg?style=flat-square)](https://github.com/loadsys/CakePHP-Serializers-Errors/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://travis-ci.org/loadsys/CakePHP-Serializers-Errors.svg?branch=master\u0026style=flat-square)](https://travis-ci.org/loadsys/CakePHP-Serializers-Errors)\n[![Coverage Status](https://coveralls.io/repos/loadsys/CakePHP-Serializers-Errors/badge.svg)](https://coveralls.io/r/loadsys/CakePHP-Serializers-Errors)\n[![Total Downloads](https://img.shields.io/packagist/dt/loadsys/cakephp-serializers-errors.svg?style=flat-square)](https://packagist.org/packages/loadsys/cakephp-serializers-errors)\n\nUsed to serialize CakePHP Errors and Exceptions, primarily as HTML, JSON or JSON API.\n\nAdds two new Exception Classes to extend from to get [JSON API](http://jsonapi.org/format/#errors) formatted error messages.\n\n## Requirements\n\n* CakePHP 2.3+\n* PHP 5.4+\n\n## Installation\n\n### Composer\n\n````bash\n$ composer require loadsys/cakephp-serializers-errors:~1.0\n````\n\n## Usage\n\n* Add this plugin to your application by adding this line to your bootstrap.php\n\n````php\nCakePlugin::load('SerializersErrors', array('bootstrap' =\u003e true));\n````\n* Update your `core.php` to use the plugin's ExceptionRenderer in place of the core's\n\n```php\nConfigure::write('Exception', array(\n\t'handler' =\u003e 'ErrorHandler::handleException',\n\t'renderer' =\u003e 'SerializersErrors.SerializerExceptionRenderer',\n\t'log' =\u003e true,\n));\n```\n\n* Once this is done Exceptions are rendered as possible, [JSON API errors](http://jsonapi.org/format/#errors), \nJSON formated errors or standard HTML responses, differing on the request `Accepts` Header. \n* So if you use:\n - `Accepts: application/vnd.api+json` JSON API Errors are returned\n - `Accepts: application/json` JSON Errors are returned\n - `Accepts: */*` Normal CakePHP HTML Style Errors are returned\n* If you build custom Exceptions that extend `BaseSerializerException` you get \nExceptions that enable the full feature set of [JSON API errors](http://jsonapi.org/format/#errors)\nin addition to be rendering in the pattern described above.\n\n## Sample Responses\n\nHere are some sample response for the different Exception classes.\n\n### BaseSerializerException\n\n#### Accepts: application/vnd.api+json\n\nMatches the format expected in [JSON API](http://jsonapi.org/format/#errors)\n\n```php\nthrow 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())\n```\n\n```javascript\n{\n\t\"errors\": [\n\t\t{\n\t\t\t\"id\": \"Custom ID For Error\",\n\t\t\t\"href\": \"http://docs.domain.com/api/v1/custom-id-for-error\",\n\t\t\t\"status\": \"401\",\n\t\t\t\"code\": \"401\",\n\t\t\t\"title\": \"Title of the Error\",\n\t\t\t\"detail\": \"More Detailed information\",\n\t\t\t\"links\": [],\n\t\t\t\"paths\": []\n\t\t}\n\t]\n}\n```\n\n#### Accepts: application/json\n\n```php\nthrow 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())\n```\n\n```javascript\n{\n\t\"id\": \"Custom ID For Error\",\n\t\"href\": \"http://docs.domain.com/api/v1/custom-id-for-error\",\n\t\"status\": \"400\",\n\t\"code\": \"400\",\n\t\"detail\": \"Something failed\",\n\t\"links\": [],\n\t\"paths\": []\n}\n```\n\n### ValidationBaseSerializerException\n\n#### Accepts: application/vnd.api+json\n\nMatches the format expected in [JSON API](http://jsonapi.org/format/#errors)\n\n```php\nthrow new ValidationBaseSerializerException(\"This is a message.\", $this-\u003eModelName-\u003einvalidFields(), 422, \"Custom ID For Error\", \"http://docs.domain.com/api/v1/custom-id-for-error\", array(), array())\n```\n\n```javascript\n{\n\t\"errors\": {\n\t\t\"id\": \"Custom ID For Error\",\n\t\t\"href\": \"http://docs.domain.com/api/v1/custom-id-for-error\",\n\t\t\"status\": \"400\",\n\t\t\"code\": \"400\",\n\t\t\"title\": \"This is a message.\",\n\t\t\"detail\": {\n\t\t\t\"username\": [\n\t\t\t\t\"Username can not be empty\",\n\t\t\t\t\"Username can only be alphanumeric characters\"\n\t\t\t],\n\t\t\t\"first_name\": [\n\t\t\t\t\"First Name must be longer than 4 characters\"\n\t\t\t]\n\t\t},\n\t\t\"links\": [],\n\t\t\"paths\": []\n\t}\n}\n```\n\n#### Accepts: application/json\n\nMatches the format expected in [Ember.js DS.Errors Class](http://emberjs.com/api/data/classes/DS.Errors.html)\n\n```php\n$invalidFields = $this-\u003eModelName-\u003einvalidFields();\nthrow new ValidationBaseSerializerException(\"This is a message.\", $invalidFields, 422, \"Custom ID For Error\", \"http://docs.domain.com/api/v1/custom-id-for-error\", array(), array())\n```\n\n```javascript\n{\n\t\"errors\": {\n\t\t\"name\": [\n\t\t\t\"Name must not be empty.\", \n\t\t\t\"Name must be only alphanumeric characters\"\n\t\t],\n\t\t\"status\": [\n\t\t\t\"Status? must be true or false.\"\n\t\t],\n\t\t\"SubModel\": [\n\t\t\t{\n\t\t\t\t\"options\": [\n\t\t\t\t\t\"Options must take the form `first|second|third` and `formula` must be empty.\"\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t}\n}\n```\n\n## Contributing\n\n### Reporting Issues\n\nPlease use [GitHub Isuses](https://github.com/loadsys/CakePHP-Serializers-Errors/issues) for listing any known defects or issues.\n\n### Development\n\nWhen developing this plugin, please fork and issue a PR for any new development.\n\nThe Complete Test Suite for the plugin can be run via this command:\n\n`./lib/Cake/Console/cake test SerializersErrors AllSerializersErrors`\n\n## License ##\n\n[MIT](https://github.com/loadsys/CakePHP-Serializers-Errors/blob/master/LICENSE.md)\n\n\n## Copyright ##\n\n[Loadsys Web Strategies](http://www.loadsys.com) 2015\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsys%2Fcakephp-serializers-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floadsys%2Fcakephp-serializers-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsys%2Fcakephp-serializers-errors/lists"}