Sha256: b98821d078e14ab7116d717e153e6ab9824a172a66d3893573727f3b93182588
Contents?: true
Size: 1.57 KB
Versions: 4
Compression:
Stored size: 1.57 KB
Contents
module NxtHttpClient class Error < StandardError def initialize(response, message = nil) @response = response.blank? ? Typhoeus::Response.new : response @id = SecureRandom.uuid @message = message || default_message super(@message) end attr_reader :response, :id, :message alias_method :to_s, :message def default_message "NxtHttpClient::Error::#{response_code}" end def to_h { id: id, url: url, response_code: response_code, request_options: request_options, response_headers: response_headers, body: body } end def body if response_content_type&.starts_with?('application/json') JSON.parse(response.body) else response.body end rescue ::JSON::JSONError response.body end def response_code response.code || 0 end def request @request ||= response.request || Typhoeus::Request.new('/dev/null', {}) end def url request.url end def request_options @request_options ||= (request.original_options || {}).with_indifferent_access end def request_headers @request_headers ||= (request.original_options[:headers] || {}).with_indifferent_access end def response_options @response_options ||= (response.options || {}).with_indifferent_access end def response_headers @response_headers ||= (response.headers || {}).with_indifferent_access end def response_content_type response_headers['Content-Type'] end end end
Version data entries
4 entries across 4 versions & 1 rubygems