From cbff3d00ce86ed0f5c5cd460a49304b1f832797d Mon Sep 17 00:00:00 2001 From: Jacopo Date: Mon, 29 Sep 2025 09:29:30 +0200 Subject: [PATCH] Wrap PoolTimeoutErrors with ActionPushNative::ConnectionPoolTimeoutError --- app/jobs/action_push_native/notification_job.rb | 2 +- lib/action_push_native/errors.rb | 1 + lib/action_push_native/service/network_error_handling.rb | 2 +- .../action_push_native/install/templates/config/push.yml.tt | 4 ++-- test/dummy/config/push.yml | 4 ++-- test/lib/action_push_native/service/apns_test.rb | 3 ++- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/jobs/action_push_native/notification_job.rb b/app/jobs/action_push_native/notification_job.rb index eaeaed3..ccf4574 100644 --- a/app/jobs/action_push_native/notification_job.rb +++ b/app/jobs/action_push_native/notification_job.rb @@ -40,7 +40,7 @@ def exponential_backoff_delay(executions) with_options retry_options do retry_on TimeoutError, wait: 1.minute - retry_on ConnectionError, HTTPX::PoolTimeoutError, attempts: 20 + retry_on ConnectionError, ConnectionPoolTimeoutError, attempts: 20 # Altough unexpected, these are short-lived errors that can be retried most of the times. retry_on ForbiddenError, BadRequestError diff --git a/lib/action_push_native/errors.rb b/lib/action_push_native/errors.rb index 631f2b9..8b790f7 100644 --- a/lib/action_push_native/errors.rb +++ b/lib/action_push_native/errors.rb @@ -3,6 +3,7 @@ module ActionPushNative class TimeoutError < StandardError; end class ConnectionError < StandardError; end + class ConnectionPoolTimeoutError < StandardError; end class BadRequestError < StandardError; end class ForbiddenError < StandardError; end diff --git a/lib/action_push_native/service/network_error_handling.rb b/lib/action_push_native/service/network_error_handling.rb index b2552fa..c88dd62 100644 --- a/lib/action_push_native/service/network_error_handling.rb +++ b/lib/action_push_native/service/network_error_handling.rb @@ -4,7 +4,7 @@ module ActionPushNative::Service::NetworkErrorHandling def handle_network_error(error) case error when HTTPX::PoolTimeoutError - raise error + raise ActionPushNative::ConnectionPoolTimeoutError, error.message when Errno::ETIMEDOUT, HTTPX::TimeoutError raise ActionPushNative::TimeoutError, error.message when Errno::ECONNRESET, Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, diff --git a/lib/generators/action_push_native/install/templates/config/push.yml.tt b/lib/generators/action_push_native/install/templates/config/push.yml.tt index 4e5c813..2fdc818 100644 --- a/lib/generators/action_push_native/install/templates/config/push.yml.tt +++ b/lib/generators/action_push_native/install/templates/config/push.yml.tt @@ -11,7 +11,7 @@ shared: topic: your.bundle.identifier # Set this to the number of threads used to process notifications (default: 5). - # When the pool size is too small a HTTPX::PoolTimeoutError error will be raised. + # When the pool size is too small a ConnectionPoolTimeoutError will be raised. # connection_pool_size: 5 # Change the request timeout (default: 30). @@ -33,7 +33,7 @@ shared: project_id: your_project_id # Set this to the number of threads used to process notifications (default: 5). - # When the pool size is too small a HTTPX::PoolTimeoutError error will be raised. + # When the pool size is too small a ConnectionPoolTimeoutError will be raised. # connection_pool_size: 5 # Change the request timeout (default: 15). diff --git a/test/dummy/config/push.yml b/test/dummy/config/push.yml index 94f90e8..93da0ae 100644 --- a/test/dummy/config/push.yml +++ b/test/dummy/config/push.yml @@ -11,7 +11,7 @@ shared: topic: your.bundle.identifier # Set this to the number of threads used to process notifications (default: 5). - # When the pool size is too small a HTTPX::PoolTimeoutError error will be raised. + # When the pool size is too small a ConnectionPoolTimeoutError will be raised. # connection_pool_size: 5 # Change the request timeout (default: 30). @@ -30,7 +30,7 @@ shared: encryption_key: <%= Rails.application.credentials.dig(:action_push_native, :fcm, :encryption_key)&.dump %> # Set this to the number of threads used to process notifications (default: 5). - # When the pool size is too small a HTTPX::PoolTimeoutError error will be raised. + # When the pool size is too small a ConnectionPoolTimeoutError will be raised. # connection_pool_size: 5 # Firebase project_id diff --git a/test/lib/action_push_native/service/apns_test.rb b/test/lib/action_push_native/service/apns_test.rb index 9615f93..c32fc00 100644 --- a/test/lib/action_push_native/service/apns_test.rb +++ b/test/lib/action_push_native/service/apns_test.rb @@ -86,9 +86,10 @@ class ApnsTest < ActiveSupport::TestCase stub_request(:post, "https://api.push.apple.com/3/device/123"). to_raise(HTTPX::PoolTimeoutError.new(5, "Timed out after 5 seconds while waiting for a connection")) - assert_raises HTTPX::PoolTimeoutError do + error = assert_raises ActionPushNative::ConnectionPoolTimeoutError do @apns.push(@notification) end + assert_equal "Timed out after 5 seconds while waiting for a connection", error.message end test "push apns payload can be overridden" do