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-7.5.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-7.4.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-7.3.1 lib/dor/services/client/response_error_formatter.rb
dor-services-client-7.3.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-7.2.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-7.1.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-7.0.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.36.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.35.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.34.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.33.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.32.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.31.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.30.1 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.30.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.29.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.28.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.27.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.26.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-6.26.0.beta.1 lib/dor/services/client/response_error_formatter.rb