Im trying to figure out how to make a custom exception behavior. When i throw a exception using
throw new \Exception('Error occurred with your request please try again');
I automatically get status 500 and the message as internal server error
However i would instead like my response to include my exception message instead of just internal server error so for it to display something like so:
{
"error":{
"code":500,
"message":"Error occurred with your request please try again"
}
}
and on top of that possibly do some extra things such as email myself the error. However I only want this to happen when i throw a \Exception as opposed to using something like
throw new HttpException
Any help or ideas on how to accomplish this.
I should also mention that I am not using Twig or any templates for this. This is strictly a API type response
try catchblock you are using?