Exception: NxtHttpClient::Error
- Inherits:
-
StandardError
- Object
- StandardError
- NxtHttpClient::Error
- Defined in:
- lib/nxt_http_client.rb,
lib/nxt_http_client/error.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#message ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute message.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Object
- #default_message ⇒ Object
-
#initialize(response, message = nil) ⇒ Error
constructor
A new instance of Error.
- #request ⇒ Object
- #request_headers ⇒ Object
- #request_options ⇒ Object
- #response_code ⇒ Object
- #response_content_type ⇒ Object
- #response_headers ⇒ Object
- #response_options ⇒ Object
- #to_h ⇒ Object
- #url ⇒ Object
- #x_request_id ⇒ Object
Constructor Details
#initialize(response, message = nil) ⇒ Error
Returns a new instance of Error.
3 4 5 6 7 8 9 |
# File 'lib/nxt_http_client/error.rb', line 3 def initialize(response, = nil) @response = response.blank? ? Typhoeus::Response.new : response @id = SecureRandom.uuid @message = || super(@message) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/nxt_http_client/error.rb', line 11 def id @id end |
#message ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute message.
11 12 13 |
# File 'lib/nxt_http_client/error.rb', line 11 def @message end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'lib/nxt_http_client/error.rb', line 11 def response @response end |
Instance Method Details
#body ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/nxt_http_client/error.rb', line 33 def body if response_content_type&.starts_with?(ApplicationJson) JSON.parse(response.body) else response.body end rescue ::JSON::JSONError response.body end |
#default_message ⇒ Object
16 17 18 |
# File 'lib/nxt_http_client/error.rb', line 16 def "#{self.class.name}::#{response_code}" end |
#request ⇒ Object
49 50 51 |
# File 'lib/nxt_http_client/error.rb', line 49 def request @request ||= response.request || Typhoeus::Request.new('/dev/null', {}) end |
#request_headers ⇒ Object
65 66 67 |
# File 'lib/nxt_http_client/error.rb', line 65 def request_headers @request_headers ||= (request.[:headers] || {}).with_indifferent_access end |
#request_options ⇒ Object
61 62 63 |
# File 'lib/nxt_http_client/error.rb', line 61 def @request_options ||= (request. || {}).with_indifferent_access end |
#response_code ⇒ Object
43 44 45 46 47 |
# File 'lib/nxt_http_client/error.rb', line 43 def response_code return response.code if response.respond_to?(:code) 0 end |
#response_content_type ⇒ Object
77 78 79 |
# File 'lib/nxt_http_client/error.rb', line 77 def response_content_type response_headers['Content-Type'] end |
#response_headers ⇒ Object
73 74 75 |
# File 'lib/nxt_http_client/error.rb', line 73 def response_headers @response_headers ||= (response.headers || {}).with_indifferent_access end |
#response_options ⇒ Object
69 70 71 |
# File 'lib/nxt_http_client/error.rb', line 69 def @response_options ||= (response. || {}).with_indifferent_access end |
#to_h ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nxt_http_client/error.rb', line 20 def to_h { id: id, url: url, response_code: response_code, request_options: , response_headers: response_headers, request_headers: request_headers, body: body, x_request_id: x_request_id } end |
#url ⇒ Object
53 54 55 |
# File 'lib/nxt_http_client/error.rb', line 53 def url request.url end |
#x_request_id ⇒ Object
57 58 59 |
# File 'lib/nxt_http_client/error.rb', line 57 def x_request_id request_headers[XRequestId] end |