Exception: Grape::Exceptions::ValidationErrors
- Defined in:
- lib/grape/exceptions/validation_errors.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Attributes inherited from Base
Instance Method Summary collapse
- #as_json(**_opts) ⇒ Object
- #full_messages ⇒ Object
-
#initialize(exceptions: [], headers: {}) ⇒ ValidationErrors
constructor
A new instance of ValidationErrors.
- #to_json(*_opts) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(exceptions: [], headers: {}) ⇒ ValidationErrors
Returns a new instance of ValidationErrors.
8 9 10 11 |
# File 'lib/grape/exceptions/validation_errors.rb', line 8 def initialize(exceptions: [], headers: {}) @errors = exceptions.flat_map(&:errors).group_by(&:params) super(message: .join(', '), status: 400, headers:) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/grape/exceptions/validation_errors.rb', line 6 def errors @errors end |
Instance Method Details
#as_json(**_opts) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/grape/exceptions/validation_errors.rb', line 13 def as_json(**_opts) errors.map do |k, v| { params: k, messages: v.map(&:to_s) } end end |
#full_messages ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/grape/exceptions/validation_errors.rb', line 26 def = errors.flat_map do |attributes, errs| errs.map do |error| translate( :format, scope: 'grape.errors', default: '%<attributes>s %<message>s', attributes: translate_attributes(attributes), message: error. ) end end .uniq! end |
#to_json(*_opts) ⇒ Object
22 23 24 |
# File 'lib/grape/exceptions/validation_errors.rb', line 22 def to_json(*_opts) as_json.to_json end |