Sha256: 1b090fc6c5f0437ff1801f5b89c9cff3a9ff80024e569ed0a96581e7fe4ccac2
Contents?: true
Size: 1.41 KB
Versions: 17
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true module Preservation class Client # Format HTTP response-related errors class ResponseErrorFormatter DEFAULT_BODY = 'Response from preservation-catalog did not contain a body. '\ 'Check honeybadger for preservation-catalog for backtraces, '\ 'and look into adding a `rescue_from` in preservation-catalog '\ 'to provide more details to the client in the future.' def self.format(response:, object_id: nil, client_method_name: nil) new(response: response, object_id: object_id, client_method_name: client_method_name).format end attr_reader :req_url, :status_msg, :status_code, :body, :object_id, :client_method_name def initialize(response:, object_id: nil, client_method_name: nil) @req_url = response.env.url @status_msg = response.reason_phrase @status_code = response.status @body = response.body.present? ? response.body : DEFAULT_BODY @object_id = object_id @client_method_name = client_method_name end def format status_info = status_msg.blank? ? status_code : "#{status_msg} (#{status_code})" object_id_info = " for #{object_id}" if object_id.present? "Preservation::Client.#{client_method_name}#{object_id_info} got #{status_info} from Preservation at #{req_url}: #{body}" end end end end
Version data entries
17 entries across 17 versions & 1 rubygems