1010use Magento \Framework \Exception \AuthorizationException ;
1111use Magento \Framework \Exception \LocalizedException ;
1212use Magento \Framework \GraphQl \Config \Element \Field ;
13- use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
1413use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
1514use Magento \Framework \GraphQl \Query \ResolverInterface ;
1615use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
17- use Magento \GraphQl \Helper \Error \AggregateExceptionMessageFormatter ;
1816use Magento \QuoteGraphQl \Model \Cart \GetCartForCheckout ;
1917use Magento \QuoteGraphQl \Model \Cart \PlaceOrder as PlaceOrderModel ;
20- use Magento \QuoteGraphQl \Model \ErrorMapper ;
21- use Magento \QuoteGraphQl \Model \QuoteException ;
18+ use Magento \QuoteGraphQl \Model \OrderErrorProcessor ;
2219use Magento \Sales \Api \OrderRepositoryInterface ;
2320use Magento \SalesGraphQl \Model \Formatter \Order as OrderFormatter ;
2421
2522/**
2623 * Resolver for placing order after payment method has already been set
27- *
28- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2924 */
3025class PlaceOrder implements ResolverInterface
3126{
@@ -34,16 +29,14 @@ class PlaceOrder implements ResolverInterface
3429 * @param PlaceOrderModel $placeOrder
3530 * @param OrderRepositoryInterface $orderRepository
3631 * @param OrderFormatter $orderFormatter
37- * @param AggregateExceptionMessageFormatter $errorMessageFormatter
38- * @param ErrorMapper $errorMapper
32+ * @param OrderErrorProcessor $orderErrorProcessor
3933 */
4034 public function __construct (
4135 private readonly GetCartForCheckout $ getCartForCheckout ,
4236 private readonly PlaceOrderModel $ placeOrder ,
4337 private readonly OrderRepositoryInterface $ orderRepository ,
4438 private readonly OrderFormatter $ orderFormatter ,
45- private readonly AggregateExceptionMessageFormatter $ errorMessageFormatter ,
46- private readonly ErrorMapper $ errorMapper
39+ private readonly OrderErrorProcessor $ orderErrorProcessor
4740 ) {
4841 }
4942
@@ -63,26 +56,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
6356 $ cart = $ this ->getCartForCheckout ->execute ($ maskedCartId , $ userId , $ storeId );
6457 $ orderId = $ this ->placeOrder ->execute ($ cart , $ maskedCartId , $ userId );
6558 $ order = $ this ->orderRepository ->get ($ orderId );
66- } catch (AuthorizationException $ exception ) {
67- throw new GraphQlAuthorizationException (
68- __ ($ exception ->getMessage ())
69- );
70- } catch (LocalizedException $ exception ) {
71- $ exception = $ this ->errorMessageFormatter ->getFormatted (
72- $ exception ,
73- __ ('Unable to place order: A server error stopped your order from being placed. ' .
74- 'Please try to place your order again ' ),
75- 'Unable to place order ' ,
76- $ field ,
77- $ context ,
78- $ info
79- );
80- $ exceptionCode = $ exception ->getCode ();
81- if (!$ exceptionCode ) {
82- $ exceptionCode = $ this ->errorMapper ->getErrorMessageId ($ exception ->getMessage ());
83- }
84-
85- throw new QuoteException (__ ($ exception ->getMessage ()), $ exception , $ exceptionCode );
59+ } catch (AuthorizationException |LocalizedException $ exception ) {
60+ return $ this ->orderErrorProcessor ->execute ($ exception , $ field , $ context , $ info );
8661 }
8762
8863 return [
@@ -91,7 +66,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value
9166 // @deprecated The order_id field is deprecated, use order_number instead
9267 'order_id ' => $ order ?->getIncrementId(),
9368 ],
94- 'orderV2 ' => $ order ? $ this ->orderFormatter ->format ($ order ) : null
69+ 'orderV2 ' => $ order ? $ this ->orderFormatter ->format ($ order ) : null ,
9570 ];
9671 }
9772}
0 commit comments