class Paperdrive::Error

Error Class

Public Class Methods

raise_from(response) click to toggle source

raise errors which corresponding to response status code

@param [Paperdrive::Client] response

# File lib/paperdrive/error.rb, line 10
def raise_from(response)
  status = response.status
  return if (200..299).cover?(status)

  klass = case status
          when 400 then Paperdrive::BadRequest
          when 401 then Paperdrive::Unauthorized
          when 429 then Paperdrive::RateLimitExceeded
          when 400..499 then Paperdrive::ClientError
          when 500 then Paperdrive::InternalServerError
          when 500..599 then Paperdrive::ServerError
          else Paperdrive::UnknownError
          end
  raise klass, "#{status}-#{response&.reason_phrase}"
end