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"
}
When I throw an Exception in a custom controller, the exception message is put in the
hydra:descriptionfield of the response only in dev envConfiguration :
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" }