Exception: Grape::Exceptions::Validation
- Defined in:
- lib/grape/exceptions/validation.rb
Constant Summary collapse
- EMPTY_BACKTRACE =
[].freeze
Constants inherited from Base
Instance Attribute Summary collapse
-
#message_key ⇒ Object
readonly
Returns the value of attribute message_key.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Attributes inherited from Base
Instance Method Summary collapse
-
#as_json(*_args) ⇒ Object
Remove all the unnecessary stuff from Grape::Exceptions::Base like status and headers when converting a validation error to json or string.
-
#errors ⇒ Object
Returns
selfso callers (e.g. ValidationErrors#initialize) can treat a singleValidationand aValidationArrayErrorswrapper uniformly via flat_map(&:errors) — Array returns flatten in, non-Array returns (i.e. thisself) append as one element. -
#initialize(params:, message: nil, status: nil, headers: nil) ⇒ Validation
constructor
A new instance of Validation.
Methods inherited from Base
Constructor Details
#initialize(params:, message: nil, status: nil, headers: nil) ⇒ Validation
Returns a new instance of Validation.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/grape/exceptions/validation.rb', line 10 def initialize(params:, message: nil, status: nil, headers: nil) @params = Array(params) if @message_key = case when Symbol then when Hash then [:key] end = () end super(status:, message:, headers:) # Pre-seed the backtrace so Ruby's raise skips capture. Validation errors are # a hot path (raised per bad attribute) and end up as 400 Bad Request responses; # backtraces here point into Grape internals and have no diagnostic value. set_backtrace(EMPTY_BACKTRACE) end |
Instance Attribute Details
#message_key ⇒ Object (readonly)
Returns the value of attribute message_key.
8 9 10 |
# File 'lib/grape/exceptions/validation.rb', line 8 def @message_key end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/grape/exceptions/validation.rb', line 8 def params @params end |
Instance Method Details
#as_json(*_args) ⇒ Object
Remove all the unnecessary stuff from Grape::Exceptions::Base like status and headers when converting a validation error to json or string
29 30 31 |
# File 'lib/grape/exceptions/validation.rb', line 29 def as_json(*_args) to_s end |
#errors ⇒ Object
Returns self so callers (e.g. ValidationErrors#initialize) can treat a single Validation and a ValidationArrayErrors wrapper uniformly via flat_map(&:errors) — Array returns flatten in, non-Array returns (i.e. this self) append as one element.
37 38 39 |
# File 'lib/grape/exceptions/validation.rb', line 37 def errors self end |