Hello, I'm setting up an api with FOSRestBundle, my api controllers don't have a view layer and return pure JSON objects ( return new JsonResponse($user); ).
Upon exceptions, I would like to return a more or less clear message for my api clients, for example,
if (!$user) throw new HttpException(404, "User {$user_id} does not exist in this context");
But what actually api returns when I throw an HttpException(404) is this:
{"error":{"code":404,"message":"Not Found"}}
This is, a generic message, not mine (the json structure is ok for me, only the message would be better).
I tried implementing a custom exception wrapper and config it in config.yml fos_rest/view/exception_wrapper_handler but I'm not able to set it to work. All tutorials I find are referred to the view layer and I don't manage to put it to work.
Thank you