17
17
use Magento \GraphQl \Helper \Error \AggregateExceptionMessageFormatter ;
18
18
use Magento \QuoteGraphQl \Model \Cart \GetCartForCheckout ;
19
19
use Magento \QuoteGraphQl \Model \Cart \PlaceOrder as PlaceOrderModel ;
20
+ use Magento \QuoteGraphQl \Model \ErrorMapper ;
20
21
use Magento \QuoteGraphQl \Model \QuoteException ;
21
22
use Magento \Sales \Api \OrderRepositoryInterface ;
22
23
use Magento \SalesGraphQl \Model \Formatter \Order as OrderFormatter ;
@@ -32,13 +33,15 @@ class PlaceOrder implements ResolverInterface
32
33
* @param OrderRepositoryInterface $orderRepository
33
34
* @param OrderFormatter $orderFormatter
34
35
* @param AggregateExceptionMessageFormatter $errorMessageFormatter
36
+ * @param ErrorMapper $errorMapper
35
37
*/
36
38
public function __construct (
37
39
private readonly GetCartForCheckout $ getCartForCheckout ,
38
40
private readonly PlaceOrderModel $ placeOrder ,
39
41
private readonly OrderRepositoryInterface $ orderRepository ,
40
42
private readonly OrderFormatter $ orderFormatter ,
41
- private readonly AggregateExceptionMessageFormatter $ errorMessageFormatter
43
+ private readonly AggregateExceptionMessageFormatter $ errorMessageFormatter ,
44
+ private readonly ErrorMapper $ errorMapper
42
45
) {
43
46
}
44
47
@@ -72,7 +75,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
72
75
$ context ,
73
76
$ info
74
77
);
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 );
76
84
}
77
85
78
86
return [
0 commit comments