autologic-web/symfony-json-exceptions

Graceful Symfony API errors

0.1.4 2018-06-07 14:47 UTC

This package is auto-updated.

Last update: 2025-03-11 00:35:46 UTC


README

Build Status StyleCI Maintainability Test Coverage

Handle exceptions gracefully in your Symfony APIs.

$ 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+:

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:

{
    "errors": [
        {
            "title": "Not found",
            "detail": "No route found for \"GET /api/silly\"",
            "status": 404
        }
    ]
}

Credit to @dannym87 for first implementing this in one of our services. It's now a library for re-use.