Skip to content

Commit 2bd025b

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-8623' into spartans_pr_06092023
2 parents 93f06c8 + cab0078 commit 2bd025b

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/CartTotalsTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\GraphQl\Quote\Guest;
99

1010
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1112
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1213
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1314
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
@@ -315,6 +316,25 @@ public function testGetSelectedShippingMethodFromCustomerCart()
315316
$this->graphQlQuery($query);
316317
}
317318

319+
public function testGetCartTotalsWithNonExistingCartId(): void
320+
{
321+
$maskedQuoteId = 'NonExistingQuoteId';
322+
$query = $this->getQuery($maskedQuoteId);
323+
try {
324+
$this->graphQlQuery($query);
325+
$this->fail('Expected exception was not raised');
326+
} catch (\Exception $exception) {
327+
$response = $exception->getResponseData();
328+
$this->assertArrayHasKey('errors', $response);
329+
$actualError = reset($response['errors']);
330+
$this->assertEquals("Could not find a cart with ID \"$maskedQuoteId\"", $actualError['message']);
331+
$this->assertEquals(
332+
GraphQlNoSuchEntityException::EXCEPTION_CATEGORY,
333+
$actualError['extensions']['category']
334+
);
335+
}
336+
}
337+
318338
/**
319339
* Generates GraphQl query for retrieving cart totals
320340
*

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\Framework\GraphQl\Exception;
99

10+
use GraphQL\Error\ClientAware;
11+
use GraphQL\Error\ProvidesExtensions;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Framework\Phrase;
1214

@@ -15,9 +17,9 @@
1517
*
1618
* @api
1719
*/
18-
class GraphQlNoSuchEntityException extends NoSuchEntityException implements \GraphQL\Error\ClientAware
20+
class GraphQlNoSuchEntityException extends NoSuchEntityException implements ClientAware, ProvidesExtensions
1921
{
20-
const EXCEPTION_CATEGORY = 'graphql-no-such-entity';
22+
public const EXCEPTION_CATEGORY = 'graphql-no-such-entity';
2123

2224
/**
2325
* @var boolean
@@ -53,4 +55,15 @@ public function getCategory(): string
5355
{
5456
return self::EXCEPTION_CATEGORY;
5557
}
58+
59+
/**
60+
* Get error category
61+
*
62+
* @return array
63+
*/
64+
public function getExtensions(): array
65+
{
66+
$exceptionCategory['category'] = $this->getCategory();
67+
return $exceptionCategory;
68+
}
5669
}

0 commit comments

Comments
 (0)