Sha256: 36b64029595aef82d3864114d9baf7bbe33f77d08158b41c16fc6057e488e53e

Contents?: true

Size: 1.17 KB

Versions: 5

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

5 entries across 5 versions & 1 rubygems

Version Path
dor-services-client-2.6.1 lib/dor/services/client/response_error_formatter.rb
dor-services-client-2.6.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-2.5.1 lib/dor/services/client/response_error_formatter.rb
dor-services-client-2.5.0 lib/dor/services/client/response_error_formatter.rb
dor-services-client-2.4.0 lib/dor/services/client/response_error_formatter.rb