Module: ErrorHandlingResourcable

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/droplet_kit/error_handling_resourcable.rb', line 2

def self.included(base)
  base.send(:resources) do
    default_handler do |response|
      if (200...299).include?(response.status)
        next
      elsif response.status == 429
        error = DropletKit::RateLimitReached.new("#{response.status}: #{response.body}")
        error.limit = response.headers['RateLimit-Limit']
        error.remaining = response.headers['RateLimit-Remaining']
        error.reset_at = response.headers['RateLimit-Reset']
        raise error
      else
        raise DropletKit::Error.new("#{response.status}: #{response.body}")
      end
    end
  end
end