From 4edaebb94f10bb3ab616398ff89c27820dfaef9d Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 17 Jul 2022 17:42:12 +0200 Subject: [PATCH] Remove "Did you mean?" from api errors when a parameter is missing This isn't helpful at all for an api if you don't send a required parameter and get an error response that just tells you what parameters that were available. This is a new feature with rails >= 6.1 and ruby >= 2.7, so this just keeps the old behaviour of older rails/ruby versions. --- app/controllers/api/v1/base_controller.rb | 2 +- app/controllers/api/v1/search_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index b4e80b6f5..0097eee61 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -37,7 +37,7 @@ module Api rescue_from ActionController::ParameterMissing do |e| logger.error e.message - render_error 422, "Parameters missing or invalid: #{e.message}" + render_error 422, e.message.split("\n").first end def current_user diff --git a/app/controllers/api/v1/search_controller.rb b/app/controllers/api/v1/search_controller.rb index 0f324099b..c769cfda5 100644 --- a/app/controllers/api/v1/search_controller.rb +++ b/app/controllers/api/v1/search_controller.rb @@ -15,7 +15,7 @@ module Api require_access_token %w[public:read] end - rescue_from ActionController::ParameterMissing, RuntimeError do |e| + rescue_from RuntimeError do |e| render_error 422, e.message end