-
Notifications
You must be signed in to change notification settings - Fork 633
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
Custom Error Messages (different from #38) #66
Comments
Hi Andrew, that's an interesting idea, especially that an authorization can fail for different reasons, which should be reflected in the error message. Error messages certainly can become more user friendly. However, I feel that your approach might lead to a very deeply branched logic in the ApplicationController and also duplication of the authorization logic between Maybe we could put the error messages right in the policy, where people could plug in |
Hi! rescue_from Pundit::NotAuthorizedError do |exception|
if exception.query == 'read?' # or even exception.read?
head :not_found # obscure the fact that the resource actually exists
else
head :unauthorized
end
end @thomasklemm do you think this is a valid use case or maybe this logic should be handled at a different level? Thanks! |
@andrewpthorp @whatthewhat Good point. We're merging #114 which allows you to do that. |
I have read through the open issues, and I wanted to see if there is potential for this functionality. There are some cases in which the policies fail for different reasons.
If I have a User who has had their account suspended, I may want to tell them that they cannot
create
a newRecord
because their account is suspended. If their account is not suspended, I may tell them they cannotcreate
a newRecord
because they have exceeded their limit.Both of these happen from the same action:
I don't believe passing the third argument of a custom message here (#38) solves the problem. I do, however, believe giving the exception more details and letting the
rescue
handle it gracefully solves this and #38.If I could do this (over simplified for example):
Thoughts? I could work on a feature like this if it was a desire.
The text was updated successfully, but these errors were encountered: