Class: Dor::Services::Client::ResponseErrorFormatter
- Inherits:
-
Object
- Object
- Dor::Services::Client::ResponseErrorFormatter
- Defined in:
- lib/dor/services/client/response_error_formatter.rb
Overview
Format HTTP response-related errors
Constant Summary collapse
- 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"
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#object_identifier ⇒ Object
readonly
Returns the value of attribute object_identifier.
-
#reason_phrase ⇒ Object
readonly
Returns the value of attribute reason_phrase.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(response:, object_identifier: nil) ⇒ ResponseErrorFormatter
constructor
A new instance of ResponseErrorFormatter.
Constructor Details
#initialize(response:, object_identifier: nil) ⇒ ResponseErrorFormatter
Returns a new instance of ResponseErrorFormatter.
19 20 21 22 23 24 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 19 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 |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
17 18 19 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 17 def body @body end |
#object_identifier ⇒ Object (readonly)
Returns the value of attribute object_identifier.
17 18 19 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 17 def object_identifier @object_identifier end |
#reason_phrase ⇒ Object (readonly)
Returns the value of attribute reason_phrase.
17 18 19 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 17 def reason_phrase @reason_phrase end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
17 18 19 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 17 def status @status end |
Class Method Details
.format(response:, object_identifier: nil) ⇒ Object
13 14 15 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 13 def self.format(response:, object_identifier: nil) new(response: response, object_identifier: object_identifier).format end |
Instance Method Details
#format ⇒ Object
26 27 28 29 30 |
# File 'lib/dor/services/client/response_error_formatter.rb', line 26 def format return "#{reason_phrase}: #{status} (#{body})" if object_identifier.nil? "#{reason_phrase}: #{status} (#{body}) for #{object_identifier}" end |