Exception: NxtHttpClient::Error
- Inherits:
-
StandardError
- Object
- StandardError
- NxtHttpClient::Error
show all
- Defined in:
- lib/nxt_http_client.rb,
lib/nxt_http_client/error.rb
Defined Under Namespace
Classes: BadRequest, CertificateError, ClientError, ConnectionFailed, Forbidden, NameResolutionError, NetworkError, NotFound, ServerError, Timeout, TlsError, TooManyRequests, Unauthorized, UnprocessableEntity
Constant Summary
collapse
- CERTIFICATE_RETURN_CODES =
Cert/trust failures — mapped to non-retryable CertificateError, kept out of the generic TlsError.
%i[
peer_failed_verification ssl_certproblem ssl_cacert_badfile ssl_issuer_error ssl_crl_badfile
].freeze
- REDACTED =
'[REDACTED]'
%w[Authorization Proxy-Authorization].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response, message = nil) ⇒ Error
Returns a new instance of Error.
47
48
49
50
51
52
53
|
# File 'lib/nxt_http_client/error.rb', line 47
def initialize(response, message = nil)
@response = response.blank? ? Typhoeus::Response.new : response
@id = SecureRandom.uuid
@message = message || default_message
super(@message)
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
55
56
57
|
# File 'lib/nxt_http_client/error.rb', line 55
def id
@id
end
|
#message ⇒ Object
Also known as:
to_s
Returns the value of attribute message.
55
56
57
|
# File 'lib/nxt_http_client/error.rb', line 55
def message
@message
end
|
#response ⇒ Object
Returns the value of attribute response.
55
56
57
|
# File 'lib/nxt_http_client/error.rb', line 55
def response
@response
end
|
Class Method Details
.error_class_for(response) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/nxt_http_client/error.rb', line 15
def self.error_class_for(response)
code = response.respond_to?(:code) ? response.code.to_i : 0
return network_error_class(response.respond_to?(:return_code) ? response.return_code : nil) if code.zero?
status_error_class(code)
end
|
.from_response(response, message = nil) ⇒ Object
11
12
13
|
# File 'lib/nxt_http_client/error.rb', line 11
def self.from_response(response, message = nil)
error_class_for(response).new(response, message)
end
|
.network_error_class(return_code) ⇒ Object
.status_error_class(code) ⇒ Object
Instance Method Details
#body ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/nxt_http_client/error.rb', line 77
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
60
61
62
|
# File 'lib/nxt_http_client/error.rb', line 60
def default_message
"#{self.class.name}::#{response_code}"
end
|
#request ⇒ Object
93
94
95
|
# File 'lib/nxt_http_client/error.rb', line 93
def request
@request ||= response.request || Typhoeus::Request.new('/dev/null', {})
end
|
109
110
111
|
# File 'lib/nxt_http_client/error.rb', line 109
def
@request_headers ||= (request.original_options[:headers] || {}).with_indifferent_access
end
|
#request_options ⇒ Object
105
106
107
|
# File 'lib/nxt_http_client/error.rb', line 105
def request_options
@request_options ||= (request.original_options || {}).with_indifferent_access
end
|
#response_code ⇒ Object
87
88
89
90
91
|
# File 'lib/nxt_http_client/error.rb', line 87
def response_code
return response.code if response.respond_to?(:code)
0
end
|
#response_content_type ⇒ Object
121
122
123
|
# File 'lib/nxt_http_client/error.rb', line 121
def response_content_type
['Content-Type']
end
|
117
118
119
|
# File 'lib/nxt_http_client/error.rb', line 117
def
@response_headers ||= (response. || {}).with_indifferent_access
end
|
#response_options ⇒ Object
113
114
115
|
# File 'lib/nxt_http_client/error.rb', line 113
def response_options
@response_options ||= (response.options || {}).with_indifferent_access
end
|
#to_h ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/nxt_http_client/error.rb', line 64
def to_h
{
id: id,
url: url,
response_code: response_code,
request_options: redact_credentials(request_options),
response_headers: ,
request_headers: redact_authorization(),
body: body,
x_request_id: x_request_id
}
end
|
#url ⇒ Object
97
98
99
|
# File 'lib/nxt_http_client/error.rb', line 97
def url
request.url
end
|
#x_request_id ⇒ Object
101
102
103
|
# File 'lib/nxt_http_client/error.rb', line 101
def x_request_id
[XRequestId]
end
|