Class: PexelsApiClient::Base

Inherits:
Flexirest::Base
  • Object
show all
Defined in:
lib/pexels_api_client/base.rb

Direct Known Subclasses

Photo, Video

Instance Method Summary collapse

Instance Method Details

#rescue_errors(_name, response) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/pexels_api_client/base.rb', line 9

def rescue_errors(_name, response)
  if (400..499).cover?(response.status)
    result = JSON.parse(response.body)
    message = result['errors'] || [result['error']]
    raise BadRequestError, message.to_a.join(', ')
  elsif (500..599).cover?(response.status)
    raise ServerError, "Could not process your request: status #{response.status}"
  end
end