I am trying to figure out how to create custom exception behavior. When I throw an exception using
throw new \Exception('Error occurred with your request please try again');
I automatically get status 500 and message as an internal server error
However, instead, I would like my answer to include my exception message, and not just the internal server error, so to display something like this:
{
"error":{
"code":500,
"message":"Error occurred with your request please try again"
}
}
and, besides, perhaps some additional things, such as email error itself. However, I only want this to happen when I throw \ Exception and not use something like
throw new HttpException
Any help or ideas on how to do this.
I should also mention that I do not use Twig or any templates for this. This is strictly an API type response.
source