R
R
Roman2017-01-24 06:18:19
symfony
Roman, 2017-01-24 06:18:19

How to write a single uncaught error handler?

I am using php 7.x + Symfony 3.x + FOSRestBundle + JsonApi.
I read the documentation - all their examples are tightly tied to Twig, which I threw out of the project for good and, accordingly, solutions from there are not suitable.
Then I read the FOSRestBundle documentation and app/config/config.ymldid this:

fos_rest:
    exception:
        enabled: true
        exception_controller: 'AppBundle\Controller\ExceptionController::showAction'
        codes:
            'Symfony\Component\HttpKernel\Exception\ConflictHttpException': 409

Partially helped.
But why does my API now return three different error formats?
  1. The format described by me in the config. So it is necessary. Works in case of code likethrow new BadRequestHttpException();
  2. Some random Symfony format, I only noticed from the logs where it comes from - I didn’t understand, but I was able to call something similar with code like
    return new Response('Page not found.', Response::HTTP_NOT_FOUND);

  3. Some sort of internal symfony(?) response in the form of html pages (sic!). Fires whenever code like this is executed$someObject->someFunctionThatDoesNotExists();

How to intercept cases 2 and 3? Particularly problematic is #3.
Before using Symfony, I used a bunch of set_error_handler+ set_exception_handler+ to catch unhandled errors register_shutdown_functionand worked with them in one place. How is it accepted in Symfony? Who needs to be redefined so that no error (except for unrecoverable php fatal) passes by in some strange format not defined by me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question