-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling exceptions within controller methods #77
Comments
You are probably using a closure on a filter. If you declare the filter as $app->router->filter('auth', [MyController::class, 'checkAccess']); And in the class: class MyController
{
public function checkAccess()
{
if ($userPermission != $permission) throw new Exception("You don't have permission", 401);
}
} It'll catch it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to throw an exception in a controller method and catch that in the dispatcher/router? Controller methods are called in the
Dispatcher
usingcall_user_func_array
, which doesn't allow for catching exceptions.If not, how else would you return early from a method?
The text was updated successfully, but these errors were encountered: