Answer the question
In order to leave comments, you need to log in
How to write your own ExceptionHandler?
I am writing my own small application, using components
"symfony/routing": "^4.3",
"symfony/http-foundation": "^4.3",
"symfony/yaml": "^4.3",
"symfony/dependency-injection": "^4.3",
"monolog/monolog": "^1.24",
"sentry/sdk": "2.0",
"symfony/config": "^4.3",
"symfony/http-kernel": "^4.3",
<?php
use App\App;
use App\Services\Log;
define("BASEPATH", dirname(__DIR__));
\App\Exceptions\Handle::register(true);
$app = App::getInstance(BASEPATH);
Log::init(App::getConfig('logging'));
return $app;
Answer the question
In order to leave comments, you need to log in
I won't tell you about this handler, I didn't look inside. I suspect that it is only for development mode, not sure.
But I can tell you where to look at exactly how exceptions are intercepted, their type is determined and status codes are returned.
Here is a list of http-exclusions in Symfony, they are used for the purposes you need (remember your previous question): https://github.com/symfony/http-kernel/tree/master...
Here is the main process handler in the kernel, this when a controller action method is executed: https://github.com/symfony/symfony/blob/4.3/src/Sy...
Pay attention to try-catch catch all exceptions
And here comes the exception handler, which understands what to do with different types of exceptions, it handles the http exceptions you need: https://github.com/symfony/symfony/blob/4.3/src/Sy...
Study carefully , there is nothing super complicated
You can hook a handler to the exception event
https://symfony.com/doc/current/reference/events.html
In services, define a handler, give it the necessary tag, and that's it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question