Module: ErrorHandlingResourcable
- Included in:
- DropletKit::AccountResource, DropletKit::ActionResource, DropletKit::DomainRecordResource, DropletKit::DomainResource, DropletKit::DropletActionResource, DropletKit::DropletResource, DropletKit::DropletUpgradeResource, DropletKit::ImageActionResource, DropletKit::ImageResource, DropletKit::RegionResource, DropletKit::SSHKeyResource, DropletKit::SizeResource
- Defined in:
- lib/droplet_kit/error_handling_resourcable.rb
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 |