Exception: Dor::Services::Client::UnexpectedResponse

Inherits:
Error
  • Object
show all
Defined in:
lib/dor/services/client.rb

Overview

Error that is raised when the remote server returns some unexpected response this could be any 4xx or 5xx status (except the ones that are direct children of the Error class above)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response:, object_identifier: nil, errors: nil, graphql_errors: nil) ⇒ UnexpectedResponse

rubocop:disable Lint/MissingSuper

Parameters:

  • response (Faraday::Response)
  • object_identifier (String) (defaults to: nil)

    (nil)

  • errors (Hash<String,Object>) (defaults to: nil)

    (nil) the JSON-API errors object

  • graphql_errors (Hash<String,Object>) (defaults to: nil)

    (nil) the GraphQL errors object



51
52
53
54
55
56
# File 'lib/dor/services/client.rb', line 51

def initialize(response:, object_identifier: nil, errors: nil, graphql_errors: nil)
  @response = response
  @object_identifier = object_identifier
  @errors = errors
  @graphql_errors = graphql_errors
end

Instance Attribute Details

#errorsObject

rubocop:enable Lint/MissingSuper



59
60
61
# File 'lib/dor/services/client.rb', line 59

def errors
  @errors
end

#graphql_errorsObject

rubocop:enable Lint/MissingSuper



59
60
61
# File 'lib/dor/services/client.rb', line 59

def graphql_errors
  @graphql_errors
end

Instance Method Details

#to_sObject



61
62
63
64
65
66
67
# File 'lib/dor/services/client.rb', line 61

def to_s
  # For GraphQL errors, see https://graphql-ruby.org/errors/execution_errors
  return graphql_errors.map { |e| e['message'] }.join(', ') if graphql_errors.present?
  return errors.map { |e| "#{e['title']} (#{e['detail']})" }.join(', ') if errors.present?

  ResponseErrorFormatter.format(response: @response, object_identifier: @object_identifier)
end