Sha256: 33893ceb948ff4565da86fb2a09976cd1a9ec5fd50bb748962dfc6ebf99ce52e

Contents?: true

Size: 845 Bytes

Versions: 40

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module SdrClient
  module Deposit
    # Handles unexpected responses when manipulating resources
    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. Perhaps they have expired?'
        else
          raise "unexpected response: #{response.status} #{response.body}"
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
sdr-client-1.0.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.97.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.96.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.95.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.94.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.93.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.92.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.91.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.90.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.89.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.88.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.87.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.86.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.85.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.84.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.83.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.82.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.81.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.80.0 lib/sdr_client/deposit/unexpected_response.rb
sdr-client-0.79.0 lib/sdr_client/deposit/unexpected_response.rb