1717use Magento \GraphQl \Helper \Error \AggregateExceptionMessageFormatter ;
1818use Magento \QuoteGraphQl \Model \Cart \GetCartForCheckout ;
1919use Magento \QuoteGraphQl \Model \Cart \PlaceOrder as PlaceOrderModel ;
20+ use Magento \QuoteGraphQl \Model \ErrorMapper ;
2021use Magento \QuoteGraphQl \Model \QuoteException ;
2122use Magento \Sales \Api \OrderRepositoryInterface ;
2223use Magento \SalesGraphQl \Model \Formatter \Order as OrderFormatter ;
@@ -32,13 +33,15 @@ class PlaceOrder implements ResolverInterface
3233 * @param OrderRepositoryInterface $orderRepository
3334 * @param OrderFormatter $orderFormatter
3435 * @param AggregateExceptionMessageFormatter $errorMessageFormatter
36+ * @param ErrorMapper $errorMapper
3537 */
3638 public function __construct (
3739 private readonly GetCartForCheckout $ getCartForCheckout ,
3840 private readonly PlaceOrderModel $ placeOrder ,
3941 private readonly OrderRepositoryInterface $ orderRepository ,
4042 private readonly OrderFormatter $ orderFormatter ,
41- private readonly AggregateExceptionMessageFormatter $ errorMessageFormatter
43+ private readonly AggregateExceptionMessageFormatter $ errorMessageFormatter ,
44+ private readonly ErrorMapper $ errorMapper
4245 ) {
4346 }
4447
@@ -72,7 +75,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7275 $ context ,
7376 $ info
7477 );
75- throw new QuoteException (__ ($ exception ->getMessage ()), $ exception , $ exception ->getCode ());
78+ $ exceptionCode = $ exception ->getCode ();
79+ if (!$ exceptionCode ) {
80+ $ exceptionCode = $ this ->errorMapper ->getErrorMessageId ($ exception ->getMessage ());
81+ }
82+
83+ throw new QuoteException (__ ($ exception ->getMessage ()), $ exception , $ exceptionCode );
7684 }
7785
7886 return [
0 commit comments