So we have a global error handler that will handle all http errors for the api and all 500 errors for the websites. We send back a number to the client so and put the error message with the that number in the logs so that we can look it up later.

Service Definition

This will listen to all Kernel Terminate Erorrs aka 500 errors and intercept them.

 # EVENT LISTENERS
 AppBundle\Handler\ExceptionHandler:
     class: AppBundle\Handler\ExceptionHandler
     arguments:
         - '@twig'
         - '@logger'
         - '%app.from_email%'
     tags:
         - { name: kernel.event_listener, event: kernel.exception, method: onKernelException }

Website

So for the website we pass the email and the error number to a template that is display. Here is an example.

Api

The api we receive a json response wrapped in our response envelope. It will look something like this. The Code is the the number that is provided in the exception. We set all of our codes so that we can use it here.

{
    "meta": {
        "exceptionCode": 10233243,
        "type": "exception",
        "lookupCode": "1500836462-98",
        "instance": "AppBundle\\Exception\\ProgrammerException"
    },
    "data": {
        "message": "I am a stupid exception."
    }
}