From 8225340eec7453f3f5679ce1c1552767345e68aa Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 17 Sep 2025 05:51:58 -0700 Subject: [PATCH] Fix error handling for ActionController::ParameterMissing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The render_unprocessable_entity_response method was calling to_hash on all exceptions, but ActionController::ParameterMissing doesn't have that method. Updated to handle different exception types properly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/controllers/api/v1/api_controller.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index dfcc9c5..ec4f1f0 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -88,7 +88,17 @@ module Api end def render_unprocessable_entity_response(exception) - render json: ErrorBlueprint.render_as_json(nil, errors: exception.to_hash), + error_data = if exception.respond_to?(:to_hash) + exception.to_hash + elsif exception.is_a?(ActionController::ParameterMissing) + { message: exception.message, param: exception.param } + elsif exception.respond_to?(:message) + { message: exception.message } + else + exception + end + + render json: ErrorBlueprint.render_as_json(nil, errors: error_data), status: :unprocessable_entity end