Skip to content
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

Return 404 NotFound error if ChatChannelMembership is not found #5790

Closed
mstruve opened this issue Jan 28, 2020 · 1 comment · Fixed by #5806
Closed

Return 404 NotFound error if ChatChannelMembership is not found #5790

mstruve opened this issue Jan 28, 2020 · 1 comment · Fixed by #5806
Assignees
Labels
bug always open for contribution external contributors welcome contribution is welcome! good first issue good first issues for anyone new to programming and new to the project.

Comments

@mstruve
Copy link
Contributor

mstruve commented Jan 28, 2020

In our chat_channel_memberships_controller.rb are look for a membership and then attempt to authorize it. In the event that the membership is missing we end up with the following error.
Honeybadger: https://app.honeybadger.io/fault/66984/aa161bc85a5f59b582b7949c2a14d83c
Error:

Pundit::NotDefinedError: unable to find policy `NilClassPolicy` for `nil`
chat_channel_memberships_controller.rb  6 find_by_chat_channel_id(...)
[PROJECT_ROOT]/app/controllers/chat_channel_memberships_controller.rb:6:in `find_by_chat_channel_id'
4   def find_by_chat_channel_id
5     @membership = ChatChannelMembership.where(chat_channel_id: params[:chat_channel_id], user_id: current_user.id).first
6     authorize @membership
7     render json: @membership.to_json(
8       only: %i[id status viewable_by chat_channel_id last_opened_at],

Rather than raising Pundit::NotDefinedError here we should be returning a 404, not_found status. ApplicationController has a handy not_found method that you can use to do this. I think you will want to implement a solution similar to this one.

@mstruve mstruve added bug always open for contribution good first issue good first issues for anyone new to programming and new to the project. external contributors welcome contribution is welcome! honeybadger labels Jan 28, 2020
@majakomel
Copy link
Contributor

I'll work on this 🙋🏼‍♀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug always open for contribution external contributors welcome contribution is welcome! good first issue good first issues for anyone new to programming and new to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants