Exception: Grape::Exceptions::Validation

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/exceptions/validation.rb

Constant Summary

Constants inherited from Base

Base::MESSAGE_STEPS

Instance Attribute Summary collapse

Attributes inherited from Base

#headers, #status

Instance Method Summary collapse

Methods inherited from Base

#[]

Constructor Details

#initialize(params:, message: nil, status: nil, headers: nil) ⇒ Validation

Returns a new instance of Validation.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/grape/exceptions/validation.rb', line 8

def initialize(params:, message: nil, status: nil, headers: nil)
  @params = Array(params)
  if message
    @message_key = case message
                   when Symbol then message
                   when Hash then message[:key]
                   end
    message = translate_message(message)
  end

  super(status:, message:, headers:)
end

Instance Attribute Details

#message_keyObject (readonly)

Returns the value of attribute message_key.



6
7
8
# File 'lib/grape/exceptions/validation.rb', line 6

def message_key
  @message_key
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/grape/exceptions/validation.rb', line 6

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



23
24
25
# File 'lib/grape/exceptions/validation.rb', line 23

def as_json(*_args)
  to_s
end