Exception: Grape::Exceptions::Validation

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

Constant Summary

Constant Summary

Constants inherited from Base

Base::BASE_ATTRIBUTES_KEY, Base::BASE_MESSAGES_KEY, Base::FALLBACK_LOCALE

Instance Attribute Summary collapse

Attributes inherited from Base

#headers, #message, #status

Instance Method Summary collapse

Methods inherited from Base

#[]

Constructor Details

#initialize(args = {}) ⇒ Validation



8
9
10
11
12
13
# File 'lib/grape/exceptions/validation.rb', line 8

def initialize(args = {})
  raise "Param is missing:" unless args.has_key? :param
  @param = args[:param]
  args[:message] = translate_message(args[:message_key]) if args.has_key? :message_key
  super
end

Instance Attribute Details

#paramObject

Returns the value of attribute param



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

def param
  @param
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



17
18
19
# File 'lib/grape/exceptions/validation.rb', line 17

def as_json(*args)
  to_s
end

#to_sObject



21
22
23
# File 'lib/grape/exceptions/validation.rb', line 21

def to_s
  message
end