FOSRestBundle: exception message

1,176 views
Skip to first unread message

nzurita

unread,
Jul 31, 2014, 1:55:43 PM7/31/14
to resting-wi...@googlegroups.com
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

Lukas Smith

unread,
Jul 31, 2014, 3:18:58 PM7/31/14
to nzurita, resting-wi...@googlegroups.com
for security reasons FOSRestBundle by default does not expose error messages of Exceptions. Instead it uses a whitelist approach. I am on the train right now but check the docs. BTW for this reason I actually recommend to make app specific exceptions so that you have tighter control over which exception messages you actually expose.

regards,
Lukas

Norberto Zurita

unread,
Jul 31, 2014, 6:20:12 PM7/31/14
to resting-wi...@googlegroups.com

El 31/07/2014 21:18, Lukas Smith escribió:
> I actually recommend to make app specific exceptions so that you have tighter control over which exception messages you actually expose.

Could you guide me through this proccess? I'm not being lucky with this:

exception:
codes:
'Symfony\Component\HttpKernel\Exception\HttpException': 406
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
'Symfony\Component\HttpKernel\Exception\HttpException': true
'Doctrine\ORM\OptimisticLockException': true

Thank you

Di majo

unread,
May 8, 2024, 12:25:26 PM5/8/24
to RESTing with Symfony
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638

Reply all
Reply to author
Forward
0 new messages