Fix error handling for ActionController::ParameterMissing

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 <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-09-17 05:51:58 -07:00
parent 07e5488e0b
commit 8225340eec

View file

@ -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