https://github.com/autologic-web/symfony-json-exceptions
Automatically convert exceptions to JSON for APIs in Symfony 2, 3 & 4
https://github.com/autologic-web/symfony-json-exceptions
exceptions json symfony
Last synced: 2 months ago
JSON representation
Automatically convert exceptions to JSON for APIs in Symfony 2, 3 & 4
- Host: GitHub
- URL: https://github.com/autologic-web/symfony-json-exceptions
- Owner: autologic-web
- Created: 2018-06-07T10:08:53.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-23T10:19:07.000Z (over 6 years ago)
- Last Synced: 2025-12-14T15:40:33.615Z (7 months ago)
- Topics: exceptions, json, symfony
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Symfony JSON Exceptions
[](https://travis-ci.org/autologic-web/symfony-json-exceptions) [](https://styleci.io/repos/136459077) [](https://codeclimate.com/github/autologic-web/symfony-json-exceptions/maintainability) [](https://codeclimate.com/github/autologic-web/symfony-json-exceptions/test_coverage)
### Handle exceptions gracefully in your Symfony APIs.
```bash
$ composer install autologic-web/symfony-json-exceptions
```
Include the bundle in `config/bundles.php` in Symfony 4+ or in `AppKernel.php` in Symfony 2+ and you're done for production.
If you want to use pretty exceptions in dev, add the following to the root level of your config, or a new file in Symfony 4+:
```yaml
autologic_json_exceptions:
pretty_dev: true
```
Compatible with Symfony 2, 3 & 4. PHP 5.3 to 7.2.
Returns consistently formatted errors with title, detail and status. Not found example:
```json
{
"errors": [
{
"title": "Not found",
"detail": "No route found for \"GET /api/silly\"",
"status": 404
}
]
}
```
Credit to [@dannym87](https://github.com/dannym87) for first implementing this in one of our services. It's now a library for re-use.