Sha256: 98a419a962cf4fc6353d10d29c3692fa2d34fe08c9136e4030b7b2aa07fbb77c

Contents?: true

Size: 1.17 KB

Versions: 171

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Dor
  module Services
    class Client
      # Format HTTP response-related errors
      class ResponseErrorFormatter
        DEFAULT_BODY = "Response from dor-services-app did not contain a body. \
                        Check honeybadger for dor-services-app for backtraces, \
                        and look into adding a `rescue_from` in dor-services-app \
                        to provide more details to the client in the future"

        def self.format(response:, object_identifier: nil)
          new(response: response, object_identifier: object_identifier).format
        end

        attr_reader :reason_phrase, :status, :body, :object_identifier

        def initialize(response:, object_identifier: nil)
          @reason_phrase = response.reason_phrase
          @status = response.status
          @body = response.body.present? ? response.body : DEFAULT_BODY
          @object_identifier = object_identifier
        end

        def format
          return "#{reason_phrase}: #{status} (#{body})" if object_identifier.nil?

          "#{reason_phrase}: #{status} (#{body}) for #{object_identifier}"
        end
      end
    end
  end
end

Version data entries

171 entries across 171 versions & 1 rubygems

Version Path
dor-services-client-3.8.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.7.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.6.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.5.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.4.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.3.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.2.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.1.1 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.1.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-3.0.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-2.6.2 lib/dor/services/client/response_error_formatter.rb