Sha256: b438cc03890a8b43ba6bc46ba54f27ead65b98026b3f073c04b855c36792be49

Contents?: true

Size: 798 Bytes

Versions: 8

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

module SdrClient
  class RedesignedClient
    # Handles unexpected responses
    class UnexpectedResponse
      # Raised when there is a request error (e.g.: a cocina-models version mismatch)
      class BadRequest < StandardError; end
      # Raised when there is a problem with the credentials
      class Unauthorized < StandardError; end

      # @param [Faraday::Response] response
      def self.call(response)
        case response.status
        when 400
          raise BadRequest, "There was an error with your request: #{response.body}"
        when 401
          raise Unauthorized, 'There was an error with your credentials.'
        else
          raise "unexpected response: #{response.status} #{response.body}"
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sdr-client-2.18.0 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.17.0 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.16.0 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.13.2 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.13.1 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.13.0 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.13.0.beta2 lib/sdr_client/redesigned_client/unexpected_response.rb
sdr-client-2.13.0.beta1 lib/sdr_client/redesigned_client/unexpected_response.rb