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 @moderatable Is Not Found #5791

Closed
mstruve opened this issue Jan 28, 2020 · 1 comment
Closed

Return 404 NotFound error if @moderatable Is Not Found #5791

mstruve opened this issue Jan 28, 2020 · 1 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.

Comments

@mstruve
Copy link
Contributor

mstruve commented Jan 28, 2020

In the event that an article can't be found, we should exit this action early and return a 404 not found error rather than trying and failing to continue to load necessary models.
Honeybadger: https://app.honeybadger.io/fault/66984/184d0d115e69e18889765fd6ffd15d6a
Error:

NoMethodError: undefined method `id' for nil:NilClass
moderations_controller.rb  22 article(...)
[PROJECT_ROOT]/app/controllers/moderations_controller.rb:22:in `article'
20     @moderatable = Article.find_by(slug: params[:slug])
21     @tag_moderator_tags = Tag.with_role(:tag_moderator, current_user)
22     @adjustments = TagAdjustment.where(article_id: @moderatable.id)
23     @already_adjusted_tags = @adjustments.map(&:tag_name).join(", ")
24     @allowed_to_adjust = @moderatable.class.name == "Article" && (current_user.has_role?(:super_admin) || @tag_moderator_tags.any

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.

@citizen428
Copy link
Contributor

Closed via #5999

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