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.

Fixed API error reporting to actually use the Error reporter for all … (#12067)

Damian Legawiece3d65d14a0e6
diff --git a/api/app/controllers/spree/api/v2/base_controller.rb b/api/app/controllers/spree/api/v2/base_controller.rb
index 02760585d3..144c6a8b4f 100644
--- a/api/app/controllers/spree/api/v2/base_controller.rb
+++ b/api/app/controllers/spree/api/v2/base_controller.rb
@@ -142,11 +142,15 @@ module Spree
}
end
- def record_not_found
+ def record_not_found(exception)
+ result = error_handler.call(exception: exception, opts: { user: spree_current_user })
+
render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)
end
def access_denied(exception)
+ result = error_handler.call(exception: exception, opts: { user: spree_current_user })
+
render_error_payload(exception.message, 403)
end
@@ -155,6 +159,8 @@ module Spree
end
def gateway_error(exception)
+ result = error_handler.call(exception: exception, opts: { user: spree_current_user })
+
render_error_payload(exception.message)
end
diff --git a/api/spec/requests/spree/api/v2/errors_spec.rb b/api/spec/requests/spree/api/v2/errors_spec.rb
index 22bf101e81..ae1fcc2c53 100644
--- a/api/spec/requests/spree/api/v2/errors_spec.rb
+++ b/api/spec/requests/spree/api/v2/errors_spec.rb
@@ -28,6 +28,16 @@ describe 'API v2 Errors spec', type: :request do
it 'returns proper error message' do
expect(json_response['error']).to eq('You are not authorized to access this page.')
end
+
+ it 'calls error handler' do
+ expect_next_instance_of(::Spree::Api::ErrorHandler) do |instance|
+ expect(instance).to receive(:call).with(
+ exception: instance_of(CanCan::AccessDenied),
+ opts: { user: user }
+ )
+ end
+ patch '/api/v2/storefront/cart/empty', headers: headers_bearer
+ end
end
context 'expired token failure' do