Exception: Basecamp::ValidationError

Inherits:
Error
  • Object
show all
Defined in:
lib/basecamp/validation_error.rb

Overview

Raised for validation errors (400, 422).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, hint: nil, http_status: 400, field_errors: nil) ⇒ ValidationError

Returns a new instance of ValidationError.



15
16
17
18
19
20
21
22
23
# File 'lib/basecamp/validation_error.rb', line 15

def initialize(message, hint: nil, http_status: 400, field_errors: nil)
  super(
    code: ErrorCode::VALIDATION,
    message: message,
    hint: hint,
    http_status: http_status
  )
  @field_errors = field_errors
end

Instance Attribute Details

#field_errorsHash{String => Array<String>}? (readonly)

Returns field-keyed validation messages from a 400/422 body — either => {"field" => ["msg"]}, the Rails RecordInvalid rendering, or the same map with no wrapper at all (=> ["msg"]), which some controllers emit. Nil for every other error shape. The flattened form is also folded into the message; this slot preserves the raw, untruncated per-field messages.

Returns:

  • (Hash{String => Array<String>}, nil)

    field-keyed validation messages from a 400/422 body — either => {"field" => ["msg"]}, the Rails RecordInvalid rendering, or the same map with no wrapper at all (=> ["msg"]), which some controllers emit. Nil for every other error shape. The flattened form is also folded into the message; this slot preserves the raw, untruncated per-field messages.



13
14
15
# File 'lib/basecamp/validation_error.rb', line 13

def field_errors
  @field_errors
end