DEV: Return 400 instead of 500 for invalid top period (#13828)

* DEV: Return 400 instead of 500 for invalid top period

This change will prevent a fatal 500 error when passing in an invalid
period param value to the `/top` route.

* Check if the method exists first

I couldn't get `ListController.respond_to?` to work, but was still able
to check if the method exists with
`ListController.action_methods.include?`. This way we can avoid relying
on the `NoMethodError` exception which may be raised during the course
of executing the method.

* Just check if the period param value is valid

* Use the new TopTopic.validate_period method
This commit is contained in:
Blake Erickson
2021-07-23 14:58:10 -06:00
committed by GitHub
parent bd4b87245e
commit 6ac3f1f7b5
2 changed files with 18 additions and 0 deletions

View File

@ -259,6 +259,7 @@ class ListController < ApplicationController
options ||= {}
period = params[:period]
period ||= ListController.best_period_for(current_user.try(:previous_visit_at), options[:category])
TopTopic.validate_period(period)
public_send("top_#{period}", options)
end