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.
23 24 25 26 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 23 def initialize(response) @response = response super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
20 21 22 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 20 def response @response end |
Class Method Details
.generate(response) ⇒ Object
15 16 17 18 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 15 def self.generate(response) error = KNOWN_ERRORS[response.status] SimpleJSONAPIClient::Errors.const_get(error).new(response) end |
Instance Method Details
#codes ⇒ Object
47 48 49 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 47 def codes @codes ||= errors.map { |error| error['code'] }.compact end |
#details ⇒ Object
51 52 53 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 51 def details @details ||= errors.map { |error| error['detail'] }.compact end |
#errors ⇒ Object
28 29 30 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 28 def errors Array(body['errors']) end |
#full_message ⇒ Object
42 43 44 45 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 42 def "The API returned a #{status} error status and this content:\n" + pretty_printed_response.each_line.map { |line| " #{line}" }.join end |
#message ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/simple_jsonapi_client/errors/api_error.rb', line 32 def if !codes.empty? elsif !details.empty? else end end |