I have Symfony application and I use FOSRestBundle with AngularJS. My Symfony application haven't any views.
I want to show in AngularJS messages about information received from server, with ngToast module.
If I create something or update it it's easy to show. But If server throw some exception? For example Angular client trying get item with wrong ID or this user have no acces to do this action? In this case server will throw exception, but I want to show appropriate message.
Can symfony catch this exception and for example translate it to Response object? For example - if I have no access exception symfony should catch it and make something like this:
return new Response(400, "You don't have permission to acces this route");
and Angular will get:
{
"code": 400,
"message": "You don't have permission to acces this route"
}
Is it possible? How should I do it? Maybe I should do it other way.