We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
First, uncomment or add new label to the custom_codes
custom_codes
validation_failed: { code: 1020, http_status: 422, validation_errors: :active_record }
Notice validation_errors option.
validation_errors
Uncomment or add the ActiveRecord::RecordInvalid to the error_dictionary:
ActiveRecord::RecordInvalid
error_dictionary
ActiveRecord::RecordInvalid => :validation_failed,
Then use ActiveModel::Model validations:
ActiveModel::Model
# Model class User < ApplicationRecord validates :username, presence: true end # Anywhere you create or update the model instance user = User.create!
Be sure to use error throwing methods, like save! or create! etc.
save!
create!
The errors will be rendered like this:
{ "code":2001, "message":"Authentication needed", "payload":{ "User":[ { "username":"is required" } ] } }