Handle Validation Errors
Automatic Error Handling
struct CreateUserEndpoint
include Azu::Endpoint(CreateUserRequest, UserResponse)
post "/users"
def call : UserResponse
# If validation fails, Azu raises ValidationError automatically
# The error handler converts it to a 422 response
UserResponse.new(User.create!(create_user_request))
end
endDefault Error Response
{
"errors": [
{"field": "name", "message": "can't be blank"},
{"field": "email", "message": "is invalid"}
]
}Custom Error Responses
Manual Validation Handling
Model Validation Errors
Custom Error Handler
Collecting All Errors
Displaying Errors to Users
Internationalization
See Also
Last updated
Was this helpful?
