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:
parent
07e5488e0b
commit
8225340eec
1 changed files with 11 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue