Sha256: 9c403a959260f93695e113e110213e0e630f998af2cbfe4dfa15a9c575d5aa21

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

class FolioClient
  # Handles unexpected responses when communicating with Folio
  class UnexpectedResponse
    # @param [Faraday::Response] response
    def self.call(response)
      case response.status
      when 401
        raise UnauthorizedError, "There was a problem with the access token: #{response.body}"
      when 403
        raise ForbiddenError, "The operation requires privileges which the client does not have: #{response.body}"
      when 404
        raise ResourceNotFound, "Endpoint not found or resource does not exist: #{response.body}"
      when 422
        raise UnauthorizedError, "There was a problem fetching the access token: #{response.body} "
      when 500
        raise ServiceUnavailable, "The remote server returned an internal server error."
      else
        raise StandardError, "Unexpected response: #{response.status} #{response.body}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
folio_client-0.7.0 lib/folio_client/unexpected_response.rb
folio_client-0.6.1 lib/folio_client/unexpected_response.rb
folio_client-0.6.0 lib/folio_client/unexpected_response.rb
folio_client-0.5.0 lib/folio_client/unexpected_response.rb