Exception: SimpleJSONAPIClient::Errors::APIError
- Inherits:
-
SimpleJSONAPIClient::Error
- Object
- StandardError
- SimpleJSONAPIClient::Error
- SimpleJSONAPIClient::Errors::APIError
- Extended by:
- Forwardable
- Defined in:
- lib/simple_jsonapi_client/errors/api_error.rb
Constant Summary collapse
- KNOWN_ERRORS =
{ 400 => 'BadRequestError', 404 => 'NotFoundError', 422 => 'UnprocessableEntityError' }
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #codes ⇒ Object
- #details ⇒ Object
- #errors ⇒ Object
- #full_message ⇒ Object
-
#initialize(response) ⇒ APIError
constructor
A new instance of APIError.
- #message ⇒ Object
Constructor Details
#initialize(response) ⇒ APIError
Returns a new instance of APIError.
24 25 26 27 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 24 def initialize(response) @response = response super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
21 22 23 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 21 def response @response end |
Class Method Details
.generate(response) ⇒ Object
16 17 18 19 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 16 def self.generate(response) error = KNOWN_ERRORS[response.status] SimpleJSONAPIClient::Errors.const_get(error).new(response) end |
Instance Method Details
#codes ⇒ Object
48 49 50 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 48 def codes @codes ||= errors.map { |error| error['code'] }.compact end |
#details ⇒ Object
52 53 54 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 52 def details @details ||= errors.map { |error| error['detail'] }.compact end |
#errors ⇒ Object
29 30 31 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 29 def errors Array(body['errors']) end |
#full_message ⇒ Object
43 44 45 46 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 43 def "The API returned a #{status} error status and this content:\n" + pretty_printed_response.each_line.map { |line| " #{line}" }.join end |
#message ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 33 def if !codes.empty? elsif !details.empty? else end end |