Skip to content

hydra description for Error in prod env is not set #1586

Description

@Zayon

When I throw an Exception in a custom controller, the exception message is put in the hydra:description field of the response only in dev env

Configuration :

# src/AppBundle/Resources/config/api_resources/resources.yml
AppBundle\Entity\Book:
    itemOperations:
        special:
            route_name: 'book_special'
# app/config/routing.yml
book_special:
    path: '/books/{id}/special'
    methods:  ['GET']
    defaults:
        _controller: 'AppBundle:Book:special'
        _api_resource_class: 'AppBundle\Entity\Book'
        _api_item_operation_name: 'special'
<?php
// src/AppBundle/Controller/BookController.php

namespace AppBundle\Controller;

use AppBundle\Entity\Book;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BookController extends Controller
{
    public function specialAction($data)
    {
        throw new Exception('HERE IS MY MESSAGE');
    }
}

In dev env :

curl -X GET "http://myproject.local/app_dev.php/book/1/special" -H "accept: application/ld+json"

{
    "@context": "/app_dev.php/contexts/Error",
    "@type": "hydra:Error",
    "hydra:title": "An error occurred",
    "hydra:description": "HERE IS MY MESSAGE",
    "trace": [
        {
        }
     ]
}

In prod env :

curl -X GET "http://myproject.local/book/1/special" -H "accept: application/ld+json"

{
    "@context": "/contexts/Error",
    "@type": "hydra:Error",
    "hydra:title": "An error occurred",
    "hydra:description": "Internal Server Error"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions