Exception: Interceptors::ValidationError

Inherits:
AppError
  • Object
show all
Defined in:
lib/interceptors/validation_error.rb

Instance Attribute Summary

Attributes inherited from AppError

#code, #details, #http_status

Instance Method Summary collapse

Methods inherited from AppError

#to_h

Constructor Details

#initialize(details = nil, message: "Validation failed", code: "validation_failed", http_status: 422, **keywords) ⇒ ValidationError

Returns a new instance of ValidationError.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/interceptors/validation_error.rb', line 5

def initialize(details = nil, message: "Validation failed", code: "validation_failed", http_status: 422, **keywords)
  payload = if details.nil?
              {}
            elsif details.respond_to?(:to_hash)
              details.to_hash
            else
              { base: Array(details) }
            end

  payload.merge!(keywords) unless keywords.empty?

  super(message, code: code, http_status: http_status, details: payload)
end