Permalink
Browse files

FIX: return 400 for missing required params (#6546)

If a required param is missing return a 400 and show a message
displaying which param was missing. Added this to the application
controller so that we don't have to add this logic to every controller
action.
  • Loading branch information...
oblakeerickson authored and SamSaffron committed Oct 31, 2018
1 parent 31ad7a6 commit 589e3fcaa0c8fed0f6de6e61912c8cc577975ee0
Showing with 15 additions and 0 deletions.
  1. +4 −0 app/controllers/application_controller.rb
  2. +11 −0 spec/requests/application_controller_spec.rb
@@ -219,6 +219,10 @@ class PluginDisabled < StandardError; end
render_json_error I18n.t('read_only_mode_enabled'), type: :read_only, status: 503
end
rescue_from ActionController::ParameterMissing do |e|
render_json_error e.message, status: 400
end
def redirect_with_client_support(url, options)
if request.xhr?
response.headers['Discourse-Xhr-Redirect'] = 'true'
@@ -42,6 +42,17 @@
end
end
describe 'missing required param' do
it 'should return a 400' do
get "/search/query.json", params: { trem: "misspelled term" }
expect(response.status).to eq(400)
expect(JSON.parse(response.body)).to eq(
"errors" => ["param is missing or the value is empty: term"]
)
end
end
describe 'build_not_found_page' do
describe 'topic not found' do

0 comments on commit 589e3fc

Please sign in to comment.