FOSRestBundle: show my custom exception message
You could also throw you own exception using the following configuration:
fos_rest: exception: codes: 'My\Custom\NotFound\Exception404': 404 messages: 'My\Custom\NotFound\Exception404': true
Provide a custom message in your own exception class and it should work as expected.
On the View Layer documentation: If you don't like the default exception structure, you can provide your own implementation.
class ExceptionWrapperHandler implements ExceptionWrapperHandlerInterface{ /** * @param array $data * * @return array */ public function wrap($data) { // we get the original exception $exception = $data['exception']; // some operations // ... // return the array return array( 'code' => $code, 'message' => $message, 'value' => $value ); }}
// config.ymlfos_rest: view: exception_wrapper_handler: Namespace\To\ExceptionWrapperHandler
To display your custom exception message (simply into app/config/config.yml):
fos_rest: exception: messages: Symfony\Component\HttpKernel\Exception\HttpException: true