lib/itamae/resource/http_request.rb in itamae-1.10.4 vs lib/itamae/resource/http_request.rb in itamae-1.10.5

- old
+ new

@@ -3,10 +3,13 @@ module Itamae module Resource class HttpRequest < File RedirectLimitExceeded = Class.new(StandardError) + HTTPClientError = Class.new(StandardError) + HTTPServerError = Class.new(StandardError) + HTTPUnknownError = Class.new(StandardError) alias_method :_action_create, :action_create undef_method :action_create, :action_delete, :action_edit define_attribute :action, default: :get @@ -46,19 +49,26 @@ response = http.method(attributes.action).call(uri.request_uri, attributes.headers) when :post, :put response = http.method(attributes.action).call(uri.request_uri, attributes.message, attributes.headers) end - if response.kind_of?(Net::HTTPRedirection) + case response + when Net::HTTPSuccess + break + when Net::HTTPRedirection if redirects_followed < attributes.redirect_limit uri = URI.parse(response["location"]) redirects_followed += 1 Itamae.logger.debug "Following redirect #{redirects_followed}/#{attributes.redirect_limit}" else raise RedirectLimitExceeded end + when Net::HTTPClientError + raise HTTPClientError + when Net::HTTPServerError + raise HTTPServerError else - break + raise HTTPUnknownError end end response.body end