Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Rescue from Errno::ECONNREFUSED.

Sebastian Palma1ce8962c5f62
diff --git a/api/app/services/spree/webhooks/endpoints/make_request.rb b/api/app/services/spree/webhooks/endpoints/make_request.rb
index 8fdb185c57..eb411cc5e8 100644
--- a/api/app/services/spree/webhooks/endpoints/make_request.rb
+++ b/api/app/services/spree/webhooks/endpoints/make_request.rb
@@ -29,7 +29,7 @@ module Spree
def request_status_code
http.request(request).code.to_i
- rescue SocketError, Net::ReadTimeout
+ rescue Errno::ECONNREFUSED, Net::ReadTimeout, SocketError
0
end
diff --git a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
index 6ab51b12ff..af9451a019 100644
--- a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
+++ b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
@@ -709,7 +709,6 @@ describe 'API V2 Storefront Checkout Spec', type: :request do
# complete the checkout
patch '/api/v2/storefront/checkout/complete', headers: headers
expect(response.status).to eq(200)
- order.reload
expect(order.reload.completed_at).not_to be_nil
expect(order.state).to eq('complete')
expect(order.payments.valid.first.payment_method).to eq(payment_method)
diff --git a/api/spec/services/spree/webhooks/endpoints/make_request_spec.rb b/api/spec/services/spree/webhooks/endpoints/make_request_spec.rb
index dbcededc47..f02a4505bd 100644
--- a/api/spec/services/spree/webhooks/endpoints/make_request_spec.rb
+++ b/api/spec/services/spree/webhooks/endpoints/make_request_spec.rb
@@ -89,22 +89,21 @@ describe Spree::Webhooks::Endpoints::MakeRequest do
end
end
- context 'when the request raises a SocketError exception' do
- before do
- allow(Net::HTTP).to receive(:new).and_return(http_double)
- allow(http_double).to receive(:request) { raise SocketError }
- end
-
- it { expect(subject).to eq(true) }
- end
+ describe 'rescuing from known exceptions' do
+ shared_examples 'rescues from' do |exception|
+ before do
+ allow(Net::HTTP).to receive(:new).and_return(http_double)
+ allow(http_double).to receive(:request) { raise exception }
+ end
- context 'when the request raises a Net::ReadTimeout exception' do
- before do
- allow(Net::HTTP).to receive(:new).and_return(http_double)
- allow(http_double).to receive(:request) { raise Net::ReadTimeout }
+ it "rescues from #{exception} and returns it is a failed request" do
+ expect(subject).to eq(true)
+ end
end
- it { expect(subject).to eq(true) }
+ include_examples 'rescues from', Errno::ECONNREFUSED
+ include_examples 'rescues from', Net::ReadTimeout
+ include_examples 'rescues from', SocketError
end
context 'when the request status code is not 2xx' do