Exception: JsonapiErrorsHandler::Errors::Invalid

Inherits:
StandardError
  • Object
show all
Defined in:
lib/jsonapi_errors_handler/errors/invalid.rb

Overview

Handles serialization of invalid HTTP error (422 status code)

Instance Attribute Summary

Attributes inherited from StandardError

#detail, #source, #status, #title

Instance Method Summary collapse

Methods inherited from StandardError

#to_h, #to_s

Constructor Details

#initialize(errors: {}) ⇒ Invalid

Returns a new instance of Invalid.



8
9
10
11
12
# File 'lib/jsonapi_errors_handler/errors/invalid.rb', line 8

def initialize(errors: {})
  @errors = errors
  @status = 422
  @title = 'Invalid request'
end

Instance Method Details

#serializable_hashObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/jsonapi_errors_handler/errors/invalid.rb', line 14

def serializable_hash
  errors.reduce([]) do |r, (att, msg)|
    r << {
      status: status.to_s,
      title: title,
      detail: msg,
      source: { pointer: "/data/attributes/#{att}" }
    }
  end
end