lib/satisfaction/loader.rb in ruby-satisfaction-0.6.3 vs lib/satisfaction/loader.rb in ruby-satisfaction-0.6.4

- old
+ new

@@ -46,11 +46,18 @@ raise Sfn::TooManyRedirects, "Too many redirects" unless limit > 0 get(response['location'], options.merge(:redirect_limit => limit - 1)) when Net::HTTPBadRequest raise Sfn::BadRequest, "Bad request. Response body:\n" + response.body when Net::HTTPForbidden, Net::HTTPUnauthorized - raise Sfn::AuthorizationError, "Not authorized" + message = "Not authorized" + if restricted_provider = response['X-Sfn-Restricted-Identity-Provider'] + message += " - Restricted to login provider" + if restricted_provider != 'yes' + message += " #{restricted_provider.capitalize}" + end + end + raise Sfn::AuthorizationError, message when Net::HTTPNotFound raise Sfn::NotFound, "Not found" when Net::HTTPServiceUnavailable raise Sfn::SiteMaintenance, maintenance_message(response.body) else @@ -73,13 +80,20 @@ request.set_form_data(form) http = Net::HTTP.new(uri.host, uri.port) add_authentication(request, http, options) response = execute(http, request) - + case response when Net::HTTPForbidden, Net::HTTPUnauthorized - raise Sfn::AuthorizationError, "Not authorized" + message = "Not authorized" + if restricted_provider = response['X-Sfn-Restricted-Identity-Provider'] + message += " - Restricted to login provider" + if restricted_provider != 'yes' + message += " #{restricted_provider.capitalize}" + end + end + raise Sfn::AuthorizationError, message when Net::HTTPNotFound raise Sfn::NotFound, "Not found" when Net::HTTPBadRequest raise Sfn::BadRequest, "Bad request. Response body:\n" + response.body when Net::HTTPSuccess