Class: FolioClient::UnexpectedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/folio_client/unexpected_response.rb

Overview

Handles unexpected responses when communicating with Folio

Class Method Summary collapse

Class Method Details

.call(response) ⇒ Object

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize

Parameters:

  • response (Faraday::Response)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/folio_client/unexpected_response.rb', line 9

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