mardi 29 novembre 2016

Laravel 5.3 Passing AuthorizationException a message when a Policy fails

I'm trying to find a clean way to override the AuthorizationException to take a dynamic string that can be passed back when a policy fails.

Things I know I can do are:

1) Wrap the policy in the controller with a try-catch, then rethrow a custom exception that takes a specific string, which seems a bit verbose 2) abort(403, '...') in the policy prior to returning, which seems a hacky since policies are already doing the work

and then in /Exceptions/Handler::render I can send back the response as JSON

Is there a nicer way to do this to get a message in the response of a policy failure?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire