Exception: FunApi::ValidationError

Inherits:
HTTPException show all
Defined in:
lib/funapi/exceptions.rb

Instance Attribute Summary collapse

Attributes inherited from HTTPException

#detail, #headers, #status_code

Instance Method Summary collapse

Constructor Details

#initialize(errors:, headers: nil) ⇒ ValidationError

Returns a new instance of ValidationError.



38
39
40
41
# File 'lib/funapi/exceptions.rb', line 38

def initialize(errors:, headers: nil)
  @errors = errors
  super(status_code: 422, detail: format_errors(errors), headers: headers)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



36
37
38
# File 'lib/funapi/exceptions.rb', line 36

def errors
  @errors
end

Instance Method Details

#to_responseObject



43
44
45
46
47
48
49
# File 'lib/funapi/exceptions.rb', line 43

def to_response
  [
    status_code,
    {"content-type" => "application/json"}.merge(headers),
    [JSON.dump(detail: detail)]
  ]
end