diff --git a/lib/dothoop.rb b/lib/dothoop.rb index 855ada5..90fda5f 100644 --- a/lib/dothoop.rb +++ b/lib/dothoop.rb @@ -70,4 +70,5 @@ module Dothoop NotFoundError = Class.new(Dothoop::Error) UnprocessableEntityError = Class.new(Dothoop::Error) TooManyRequestsError = Class.new(Dothoop::Error) + RedirectError = Class.new(Dothoop::Error) end diff --git a/lib/dothoop/error_handling_resourcable.rb b/lib/dothoop/error_handling_resourcable.rb index 11f8768..a824bd4 100644 --- a/lib/dothoop/error_handling_resourcable.rb +++ b/lib/dothoop/error_handling_resourcable.rb @@ -4,6 +4,8 @@ def self.included(base) default_handler do |response| if (200...299).include?(response.status) next + elsif response.status == 301 + raise Dothoop::RedirectError.new({status: response.status, body: response.body, redirect: response.headers[:location]}) elsif response.status == 401 raise Dothoop::UnauthorizedError.new("#{response.status}: #{response.body}") elsif response.status == 403 diff --git a/lib/dothoop/version.rb b/lib/dothoop/version.rb index 27b5c35..dc52a37 100644 --- a/lib/dothoop/version.rb +++ b/lib/dothoop/version.rb @@ -1,3 +1,3 @@ module Dothoop - VERSION = "0.1.6" + VERSION = "0.1.7" end diff --git a/test/lib/dothoop_test.rb b/test/lib/dothoop_test.rb index e4f39a1..0e699aa 100644 --- a/test/lib/dothoop_test.rb +++ b/test/lib/dothoop_test.rb @@ -30,4 +30,8 @@ def test_too_many_requests_error_is_initialized assert Dothoop::TooManyRequestsError end + def test_redirect_error_is_initialized + assert Dothoop::RedirectError + end + end