Exception: ChimeraHttpClient::Error
- Inherits:
-
StandardError
- Object
- StandardError
- ChimeraHttpClient::Error
- Defined in:
- lib/chimera_http_client/error.rb
Direct Known Subclasses
BadRequestError, ClientError, ConnectionError, ForbiddenError, MethodNotAllowedError, NotFoundError, RedirectionError, ResourceConflictError, ServerError, TimeoutError, UnauthorizedError, UnprocessableEntityError
Instance Attribute Summary collapse
-
#body ⇒ Object
(also: #message)
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#deserializer ⇒ Object
readonly
Returns the value of attribute deserializer.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(response, options = {}) ⇒ Error
constructor
A new instance of Error.
- #parsed_body ⇒ Object
- #to_json(_options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(response, options = {}) ⇒ Error
Returns a new instance of Error.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/chimera_http_client/error.rb', line 6 def initialize(response, = {}) @body = response.body @code = response.code @time = response.&.fetch(:total_time, nil) @response = response # contains the request @deserializer = [:deserializer][:error] super(response.body) end |
Instance Attribute Details
#body ⇒ Object (readonly) Also known as: message
Returns the value of attribute body.
3 4 5 |
# File 'lib/chimera_http_client/error.rb', line 3 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/chimera_http_client/error.rb', line 3 def code @code end |
#deserializer ⇒ Object (readonly)
Returns the value of attribute deserializer.
3 4 5 |
# File 'lib/chimera_http_client/error.rb', line 3 def deserializer @deserializer end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/chimera_http_client/error.rb', line 3 def response @response end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
3 4 5 |
# File 'lib/chimera_http_client/error.rb', line 3 def time @time end |
Instance Method Details
#error? ⇒ Boolean
17 18 19 |
# File 'lib/chimera_http_client/error.rb', line 17 def error? true end |
#parsed_body ⇒ Object
21 22 23 |
# File 'lib/chimera_http_client/error.rb', line 21 def parsed_body deserializer.call(body) end |
#to_json(_options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chimera_http_client/error.rb', line 33 def to_json( = {}) error = { code: code, error_class: self.class.name, method: http_method, url: url, message: , } return error.merge({ request: response.request.inspect }).to_json if log_requests? error.to_json end |
#to_s ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/chimera_http_client/error.rb', line 25 def to_s error = "#{self.class.name} (#{code}) #{}, URL: #{url}" return "#{error}, Request: #{response.request.inspect}" if log_requests? error end |