Skip to content

Commit c47a6a2

Browse files
committed
MC-26683: Added errors to the return model
1 parent af251eb commit c47a6a2

File tree

4 files changed

+9
-114
lines changed

4 files changed

+9
-114
lines changed

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ public function dispatch(RequestInterface $request) : ResponseInterface
160160
} catch (\Exception $error) {
161161
$result['errors'] = isset($result) && isset($result['errors']) ? $result['errors'] : [];
162162
$result['errors'][] = $this->graphQlError->create($error);
163-
// here we should have data from GraphQlCartInputException
164-
$result['data'] = $error->getData();
165163
$statusCode = ExceptionFormatter::HTTP_GRAPH_QL_SCHEMA_ERROR_STATUS;
166164
}
167165

app/code/Magento/QuoteGraphQl/Model/Cart/AddProductsToCart.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Quote\Model\Quote;
1414

1515
/**
16-
* Add products to cart
16+
* Adding products to cart using GraphQL
1717
*/
1818
class AddProductsToCart
1919
{
@@ -44,29 +44,16 @@ public function __construct(
4444
*
4545
* @param Quote $cart
4646
* @param array $cartItems
47-
* @return \Magento\Framework\GraphQl\Exception\GraphQlCartInputException
4847
* @throws GraphQlInputException
4948
* @throws \Magento\Framework\Exception\LocalizedException
5049
* @throws \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException
5150
*/
52-
public function execute(Quote $cart, array $cartItems): \Magento\Framework\GraphQl\Exception\GraphQlCartInputException
51+
public function execute(Quote $cart, array $cartItems): void
5352
{
5453
foreach ($cartItems as $cartItemData) {
5554
$this->addProductToCart->execute($cart, $cartItemData);
5655
}
5756

58-
if ($cart->getData('has_error')) {
59-
$e = new \Magento\Framework\GraphQl\Exception\GraphQlCartInputException(__('Shopping cart errors'));
60-
$errors = $cart->getErrors();
61-
foreach ($errors as $error) {
62-
/** @var MessageInterface $error */
63-
$e->addError(new GraphQlInputException(__($error->getText())));
64-
}
65-
$e->addData($cartItems);
66-
67-
throw $e;
68-
}
69-
7057
$this->cartRepository->save($cart);
7158
}
7259
}

app/code/Magento/QuoteGraphQl/Model/Resolver/CartItems.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
1314
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1415
use Magento\Quote\Model\Quote\Item as QuoteItem;
@@ -29,6 +30,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
2930
$cart = $value['model'];
3031

3132
$itemsData = [];
33+
if ($cart->getData('has_error')) {
34+
$errors = $cart->getErrors();
35+
foreach ($errors as $error) {
36+
$itemsData[] = new GraphQlInputException(__($error->getText()));
37+
}
38+
}
3239
foreach ($cart->getAllVisibleItems() as $cartItem) {
3340
/**
3441
* @var QuoteItem $cartItem

lib/internal/Magento/Framework/GraphQl/Exception/GraphQlCartInputException.php

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)