https://github.com/cerbero90/json-api-error
๐ฅ Laravel package to standardize API errors in compliance with the JSON:API spec.
https://github.com/cerbero90/json-api-error
api error-handling json json-api laravel
Last synced: about 1 month ago
JSON representation
๐ฅ Laravel package to standardize API errors in compliance with the JSON:API spec.
- Host: GitHub
- URL: https://github.com/cerbero90/json-api-error
- Owner: cerbero90
- License: mit
- Created: 2024-02-29T00:01:02.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-12T23:18:17.000Z (over 2 years ago)
- Last Synced: 2024-05-02T04:22:43.329Z (about 2 years ago)
- Topics: api, error-handling, json, json-api, laravel
- Language: PHP
- Homepage:
- Size: 85 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ๐ฅ JSON:API Error
[![Author][ico-author]][link-author]
[![PHP Version][ico-php]][link-php]
[![Laravel Version][ico-laravel]][link-laravel]
[![Build Status][ico-actions]][link-actions]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![PHPStan Level][ico-phpstan]][link-phpstan]
[![Total Downloads][ico-downloads]][link-downloads]
[![Latest Version][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![PER][ico-per]][link-per]
```json
{
"errors": [
{
"status": "422",
"title": "Unprocessable Content",
"detail": "The name field must be a string.",
"source": {
"pointer": "/name"
}
},
{
"status": "422",
"title": "Unprocessable Content",
"detail": "The name field must be at least 2 characters.",
"source": {
"pointer": "/name"
}
}
]
}
```
Laravel package to standardize API error responses in compliance with the [JSON:API spec](https://jsonapi.org/examples/#error-objects), providing:
- **consistency**: ensure uniform API error responses across all Laravel apps, adhering to a widely used standard
- **automation**: handle Laravel-specific and common HTTP exceptions automatically
- **simplicity**: focus solely on error responses without the need to implement the full JSON:API spec
- **zero configuration**: install the package with no additional configuration required
- **customization**: optionally register custom handlers, map errors to HTTP statuses or merge default data
- **localization**: translate JSON:API errors into any language
- **testability**: test error responses using the built-in testing tools
- **debugging**: inspect the original message and trace when an unexpected error occurs
## ๐ฆ Install
Via Composer:
``` bash
composer require cerbero/json-api-error
```
## ๐ฎ Usage
> [!NOTE]
> Work in progress... ๐๏ธ
> - implement `links`
> - write documentation
> - reach 100% code coverage
> - tag stable version
## ๐ Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## ๐งช Testing
``` bash
composer test
```
## ๐ Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
## ๐งฏ Security
If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.
## ๐
Credits
- [Andrea Marco Sartori][link-author]
- [All Contributors][link-contributors]
## โ๏ธ License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-author]: https://img.shields.io/badge/author-cerbero90-blue?logo=x&style=flat-square&logoSize=auto
[ico-php]: https://img.shields.io/packagist/php-v/cerbero/json-api-error?color=%23767bb5&logo=php&style=flat-square&logoSize=auto
[ico-laravel]: https://img.shields.io/static/v1?label=laravel&message=%E2%89%A59.0&color=ff2d20&logo=laravel&style=flat-square&logoSize=auto
[ico-version]: https://img.shields.io/packagist/v/cerbero/json-api-error.svg?label=version&style=flat-square
[ico-actions]: https://img.shields.io/github/actions/workflow/status/cerbero90/json-api-error/build.yml?branch=master&style=flat-square&logo=github&logoSize=auto
[ico-license]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
[ico-per]: https://img.shields.io/static/v1?label=compliance&message=PER&color=blue&style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/cerbero90/json-api-error.svg?style=flat-square&logo=scrutinizer&logoSize=auto
[ico-code-quality]: https://img.shields.io/scrutinizer/g/cerbero90/json-api-error.svg?style=flat-square&logo=scrutinizer&logoSize=auto
[ico-phpstan]: https://img.shields.io/badge/level-max-success?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGb0lEQVR42u1Xe1BUZRS/y4Kg8oiR3FCCBUySESZBRCiaBnmEsOzeSzsg+KxYYO9dEEftNRqZjx40FRZkTpqmOz5S2LsXlEZBciatkQnHDGYaGdFy1EpGMHl/p/PdFlt2rk5O+J9n5nA/vtf5ned3lnlISpRhafBlLRLHCtJGVrB/ZBDsaw2lUqzReGAC46DstTYfnSCGUjaaDvgxACo6j3vUenNdImeRXqdnWV5az5rrnzeZznj8J+E5Ftsclhf3s4J4CS/oRx5Bvon8ZU65FGYQxAwcf85a7CeRz+C41THejueydCZ7AAK34nwv3kHP/oUKdOL4K7258fF7Cud427O48RQeGkIGJ77N8fZqlrcfRP4d/x90WQfHXLeBt9dTrSlwl3V65ynWLM1SEA2qbNQckbe4Xmww10Hmy3shid0CMcmlEJtSDsl5VZBdfAgMvI3uuR+moJqN6LaxmpsOBeLCDmTifCB92RcQmbAUJvtqALc5sQr8p86gYBCcFdBq9wOin7NQax6ewlB6rqLZHf23FP10y3lj6uJtEBg2HxiVCtzd3SEwMBCio6Nh9uzZ4O/vLwOZ4OUNM2NyIGPFrvuzBG//lRPs+VQ2k1ki+ePkd84bskz7YFpYgizEz88P8vPzYffu3dDS0gJNTU1QXV0NqampRK1WIwgfiE4qhOyig0rC+pCvK8QUoML7uJVHA5kcQUp3DSpqWjc3d/Dy8oKioiLo6uqCoaEhuHb1KvT09AAhBFpbW4lOpyMyyIBQSCmoUQLQzgniNvz+obB2HS2RwBgE6dOxCyJogmNkP2u1Wrhw4QJ03+iGrR9XEd3CTNBn6eCbo40wPDwMdXV1BF1DVG5qiEtboxSUP6J71+D3NwUAhLOIRQzm7lnnhYUv7QFv/yDZ/Lm5ubK2DVI9iZ8bR8JDtEB57lNzENQN6OjoIGlpabIVZsYaMTO+hrikRRA1JxmSX9hE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RLft2PCgoKGjijBDtjrAQ7a3EdMsxzIRflAFIhPb6mHYmYwX+WBlPQgskhgVryyJCQyNyBLsBQdQ6fgsQhyt6MSOOsWZ7gbH8wETmgRKAijatNL8Ngm0xx4tLcsps0Wzx4al0jXlI40B/A3pa144MDtSgAAAAAElFTkSuQmCC&logoSize=auto
[ico-downloads]: https://img.shields.io/packagist/dt/cerbero/json-api-error.svg?style=flat-square
[link-author]: https://twitter.com/cerbero90
[link-php]: https://www.php.net
[link-laravel]: https://laravel.com
[link-packagist]: https://packagist.org/packages/cerbero/json-api-error
[link-actions]: https://github.com/cerbero90/json-api-error/actions?query=workflow%3Abuild
[link-per]: https://www.php-fig.org/per/coding-style/
[link-scrutinizer]: https://scrutinizer-ci.com/g/cerbero90/json-api-error/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/cerbero90/json-api-error
[link-downloads]: https://packagist.org/packages/cerbero/json-api-error
[link-phpstan]: https://phpstan.org/
[link-contributors]: ../../contributors