about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/subscribe_service.rb16
-rw-r--r--app/services/unsubscribe_service.rb4
2 files changed, 10 insertions, 10 deletions
diff --git a/app/services/subscribe_service.rb b/app/services/subscribe_service.rb
index 138718f14..1e7984a7f 100644
--- a/app/services/subscribe_service.rb
+++ b/app/services/subscribe_service.rb
@@ -8,28 +8,28 @@ class SubscribeService < BaseService
     response     = subscription.subscribe
 
     if response_failed_permanently?(response)
-      # An error in the 4xx range (except for 429, which is rate limiting)
-      # means we're not allowed to subscribe. Fail and move on
+      # We're not allowed to subscribe. Fail and move on.
       account.secret = ''
       account.save!
     elsif response_successful?(response)
-      # Anything in the 2xx range means the subscription will be confirmed
-      # asynchronously, we've done what we needed to do
+      # The subscription will be confirmed asynchronously.
       account.save!
     else
-      # What's left is the 5xx range and 429, which means we need to retry
-      # at a later time. Fail loudly!
+      # The response was either a 429 rate limit, or a 5xx error.
+      # We need to retry at a later time. Fail loudly!
       raise "Subscription attempt failed for #{account.acct} (#{account.hub_url}): HTTP #{response.code}"
     end
   end
 
   private
 
+  # Any response in the 3xx or 4xx range, except for 429 (rate limit)
   def response_failed_permanently?(response)
-    response.code > 299 && response.code < 500 && response.code != 429
+    (response.status.redirect? || response.status.client_error?) && !response.status.too_many_requests?
   end
 
+  # Any response in the 2xx range
   def response_successful?(response)
-    response.code > 199 && response.code < 300
+    response.status.success?
   end
 end
diff --git a/app/services/unsubscribe_service.rb b/app/services/unsubscribe_service.rb
index 1a951d1b4..6db8dbdc4 100644
--- a/app/services/unsubscribe_service.rb
+++ b/app/services/unsubscribe_service.rb
@@ -5,8 +5,8 @@ class UnsubscribeService < BaseService
     subscription = account.subscription(api_subscription_url(account.id))
     response = subscription.unsubscribe
 
-    unless response.successful?
-      Rails.logger.debug "PuSH unsubscribe for #{account.acct} failed: #{response.message}"
+    unless response.status.success?
+      Rails.logger.debug "PuSH unsubscribe for #{account.acct} failed: #{response.status}"
     end
 
     account.secret = ''