Answer the question
In order to leave comments, you need to log in
At what level in Symfony to catch errors?
Colleagues, good evening!
At what level in Symfony to catch errors so that the server always responds with valid JSON.
The idea is that for any outcome, the client always received JSON of a certain structure.
For example:
/database.getCityById?id=3538
{
"data": {
"id": 3538,
"name": "Воронеж",
"region": {
"id": 3529,
"name": "Воронежская обл."
},
"country": {
"name": "Россия",
"id": 3159
}
},
"code": 0
}
{
"code": 1,
"msg": "unknown error"
}
try {
$response = $kernel->handle($request);
} catch (Exception $e) {
$response = new JsonResponse(["code" => 1]);
$response->send();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question