Sha256: 456dee5149dd4241378a8f7bf48e409b67ae32a5fc4b4d43fb41fd0f484a0e25

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

class FolioClient
  # Handles unexpected responses when communicating with Folio
  class UnexpectedResponse
    # @param [Faraday::Response] response
    # rubocop:disable Metrics/MethodLength
    # rubocop:disable Metrics/AbcSize
    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 409
        raise ConflictError, "Resource cannot be updated: #{response.body}"
      when 422
        raise ValidationError, "There was a validation problem with the request: #{response.body}"
      when 500
        raise ServiceUnavailable, "The remote server returned an internal server error: #{response.body}"
      else
        raise StandardError, "Unexpected response: #{response.status} #{response.body}"
      end
    end
  end
  # rubocop:enable Metrics/MethodLength
  # rubocop:enable Metrics/AbcSize
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
folio_client-0.17.0 lib/folio_client/unexpected_response.rb
folio_client-0.16.0 lib/folio_client/unexpected_response.rb