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.
-
#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) ⇒ Error
constructor
A new instance of Error.
- #parsed_body ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(response) ⇒ Error
6 7 8 9 10 11 12 |
# 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 super 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 |
#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
14 15 16 |
# File 'lib/chimera_http_client/error.rb', line 14 def error? true end |
#parsed_body ⇒ Object
18 19 20 21 22 |
# File 'lib/chimera_http_client/error.rb', line 18 def parsed_body JSON.parse(body) rescue JSON::ParserError { "non_json_body" => body } end |
#to_json ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chimera_http_client/error.rb', line 32 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
24 25 26 27 28 29 30 |
# File 'lib/chimera_http_client/error.rb', line 24 def to_s error = "#{self.class.name} (#{code}) #{message}, URL: #{url}" return "#{error}, Request: #{response.request.inspect}" if log_requests? error end |