Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOSRestBundle: show my custom exception message

I'm trying to add a custom control of exceptions in FOSRestBundle but it seems to ignore my custom messages (the status code of the response is ok).

I have:

throw new HttpException(404, "User {$id} not found");

But get this json response:

{
  "error": {
    "code": 404,
    "message": "Not Found"
  }
}

So I don't find the way to show my custom message

like image 520
K. Weber Avatar asked Dec 14 '22 21:12

K. Weber


1 Answers

You could also throw you own exception using the following configuration:

fos_rest:
    exception:
        codes:
            'My\Custom\NotFound\Exception404': 404
        messages:
            'My\Custom\NotFound\Exception404': true

Provide a custom message in your own exception class and it should work as expected.

like image 70
piotr.jura Avatar answered Dec 17 '22 09:12

piotr.jura