]> cat aescling's git repositories - mastodon.git/commitdiff
Fix errors preventing UnsubscribeService from working (#4866)
authorEugen Rochko <eugen@zeonfederated.com>
Sat, 9 Sep 2017 15:36:27 +0000 (17:36 +0200)
committerGitHub <noreply@github.com>
Sat, 9 Sep 2017 15:36:27 +0000 (17:36 +0200)
app/services/unsubscribe_service.rb
spec/services/unsubscribe_service_spec.rb

index 865f783bc84adfe9fdef19e73bbdf90f7341ec0e..b99046712c7a8fe6186365c48ce2c70fba997c68 100644 (file)
@@ -4,16 +4,19 @@ class UnsubscribeService < BaseService
   def call(account)
     return if account.hub_url.blank?
 
-    @account  = account
-    @response = build_request.perform
+    @account = account
 
-    Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{@response.status}" unless @response.status.success?
+    begin
+      @response = build_request.perform
+
+      Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{@response.status}" unless @response.status.success?
+    rescue HTTP::Error, OpenSSL::SSL::SSLError => e
+      Rails.logger.debug "PuSH unsubscribe for #{@account.acct} failed: #{e}"
+    end
 
     @account.secret = ''
     @account.subscription_expires_at = nil
     @account.save!
-  rescue HTTP::Error, OpenSSL::SSL::SSLError
-    Rails.logger.debug "PuSH subscription request for #{@account.acct} could not be made due to HTTP or SSL error"
   end
 
   private
index c81772037e15ccf9a76897ade9a2e9a2c7c50061..2a02f4c75559af9a402d271fb355aa0825c7dcfc 100644 (file)
@@ -26,7 +26,7 @@ RSpec.describe UnsubscribeService do
     stub_request(:post, 'http://hub.example.com/').to_raise(HTTP::Error)
     subject.call(account)
 
-    expect(logger).to have_received(:debug).with(/PuSH subscription request for bob@example.com could not be made due to HTTP or SSL error/)
+    expect(logger).to have_received(:debug).with(/unsubscribe for bob@example.com failed/)
   end
 
   def stub_logger