-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4-develop' into 2.4-bugfixes-121621
- Loading branch information
Showing
32 changed files
with
679 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/code/Magento/CatalogInventory/Model/StockStateException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogInventory\Model; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
/** | ||
* Exception class reflecting when an operation cannot be completed due to the current stock status of an inventory item | ||
* | ||
* @api | ||
*/ | ||
class StockStateException extends LocalizedException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ogInventoryGraphQl/Helper/Error/MessageFormatters/StockStateExceptionMessageFormatter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogInventoryGraphQl\Helper\Error\MessageFormatters; | ||
|
||
use Magento\CatalogInventory\Model\StockStateException; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\GraphQl\Helper\Error\ExceptionMessageFormatterInterface; | ||
|
||
/** | ||
* Check if an internally-thrown exception is from an item stock status issue and re-throw with the message intact if so | ||
*/ | ||
class StockStateExceptionMessageFormatter implements ExceptionMessageFormatterInterface | ||
{ | ||
/** | ||
* If the thrown exception was from an item stock status issue, allow the message to go through | ||
* | ||
* @param LocalizedException $e | ||
* @param string $messagePrefix | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* | ||
* @return GraphQlInputException|null | ||
*/ | ||
public function getFormatted( | ||
LocalizedException $e, | ||
string $messagePrefix, | ||
Field $field, | ||
ContextInterface $context, | ||
ResolveInfo $info | ||
): ?GraphQlInputException { | ||
if ($e instanceof StockStateException) { | ||
return new GraphQlInputException(__("$messagePrefix: %message", ['message' => $e->getMessage()]), $e); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/code/Magento/GraphQl/Helper/Error/AggregateExceptionMessageFormatter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Helper\Error; | ||
|
||
use GraphQL\Error\ClientAware; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Framework\Phrase; | ||
|
||
/** | ||
* Class for formatting internally-thrown errors if they match allowed exception types or using a default message if not | ||
*/ | ||
class AggregateExceptionMessageFormatter | ||
{ | ||
/** | ||
* @var ExceptionMessageFormatterInterface[] | ||
*/ | ||
private $messageFormatters; | ||
|
||
/** | ||
* @param ExceptionMessageFormatterInterface[] $messageFormatters | ||
*/ | ||
public function __construct(array $messageFormatters) | ||
{ | ||
$this->messageFormatters = $messageFormatters; | ||
} | ||
|
||
/** | ||
* Format a thrown exception message if it matches one of the supplied formatters, otherwise use a default message | ||
* | ||
* @param LocalizedException $e | ||
* @param Phrase $defaultMessage | ||
* @param string $messagePrefix | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* | ||
* @return ClientAware | ||
*/ | ||
public function getFormatted( | ||
LocalizedException $e, | ||
Phrase $defaultMessage, | ||
string $messagePrefix, | ||
Field $field, | ||
ContextInterface $context, | ||
ResolveInfo $info | ||
): ClientAware { | ||
foreach ($this->messageFormatters as $formatter) { | ||
$formatted = $formatter->getFormatted($e, $messagePrefix, $field, $context, $info); | ||
if ($formatted) { | ||
return $formatted; | ||
} | ||
} | ||
return new GraphQlInputException($defaultMessage, $e); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/code/Magento/GraphQl/Helper/Error/ExceptionMessageFormatterInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Helper\Error; | ||
|
||
use GraphQL\Error\ClientAware; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* Interface for formatting reportable internal error messages | ||
*/ | ||
interface ExceptionMessageFormatterInterface | ||
{ | ||
/** | ||
* Re-throws a matching internal exception with the appropriate GraphQl exception type and user-safe message | ||
* | ||
* @param LocalizedException $e | ||
* @param string $messagePrefix | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* | ||
* @return ClientAware|null | ||
*/ | ||
public function getFormatted( | ||
LocalizedException $e, | ||
string $messagePrefix, | ||
Field $field, | ||
ContextInterface $context, | ||
ResolveInfo $info | ||
): ?ClientAware; | ||
} |
54 changes: 54 additions & 0 deletions
54
app/code/Magento/GraphQl/Helper/Error/MessageFormatters/GraphQlExceptionMessageFormatter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Helper\Error\MessageFormatters; | ||
|
||
use GraphQL\Error\ClientAware; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\GraphQl\Helper\Error\ExceptionMessageFormatterInterface; | ||
|
||
/** | ||
* Check if a thrown exception is already formatted for GraphQL and re-throw with no changes if so | ||
*/ | ||
class GraphQlExceptionMessageFormatter implements ExceptionMessageFormatterInterface | ||
{ | ||
/** | ||
* If the thrown exception is already formatted for GraphQl, re-throw it with no changes | ||
* | ||
* @param LocalizedException $e | ||
* @param string $messagePrefix | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* | ||
* @return GraphQlAlreadyExistsException|GraphQlAuthenticationException|GraphQlAuthorizationException|GraphQlInputException|GraphQlNoSuchEntityException|null | ||
*/ | ||
public function getFormatted( | ||
LocalizedException $e, | ||
string $messagePrefix, | ||
Field $field, | ||
ContextInterface $context, | ||
ResolveInfo $info | ||
): ?ClientAware { | ||
if ($e instanceof GraphQlAlreadyExistsException | ||
|| $e instanceof GraphQlAuthenticationException | ||
|| $e instanceof GraphQlAuthorizationException | ||
|| $e instanceof GraphQlInputException | ||
|| $e instanceof GraphQlNoSuchEntityException) { | ||
return $e; | ||
} | ||
return null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
.../Magento/GraphQl/Helper/Error/MessageFormatters/NoSuchEntityExceptionMessageFormatter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Helper\Error\MessageFormatters; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\GraphQl\Helper\Error\ExceptionMessageFormatterInterface; | ||
|
||
/** | ||
* Check if an internally-thrown exception is a NoSuchEntityException and re-throw with the message intact if so | ||
*/ | ||
class NoSuchEntityExceptionMessageFormatter implements ExceptionMessageFormatterInterface | ||
{ | ||
/** | ||
* If the thrown exception was a NoSuchEntityException, allow the message to go through | ||
* | ||
* @param LocalizedException $e | ||
* @param string $messagePrefix | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* | ||
* @return GraphQlNoSuchEntityException|null | ||
*/ | ||
public function getFormatted( | ||
LocalizedException $e, | ||
string $messagePrefix, | ||
Field $field, | ||
ContextInterface $context, | ||
ResolveInfo $info | ||
): ?GraphQlNoSuchEntityException { | ||
if ($e instanceof NoSuchEntityException) { | ||
return new GraphQlNoSuchEntityException(__($e->getMessage()), $e); | ||
} | ||
return null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/code/Magento/GraphQl/Helper/Error/MessageFormatters/PaymentExceptionMessageFormatter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\GraphQl\Helper\Error\MessageFormatters; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\PaymentException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\GraphQl\Helper\Error\ExceptionMessageFormatterInterface; | ||
|
||
/** | ||
* Check if an internally-thrown exception is from a payment issue and re-throw with the message intact if so | ||
*/ | ||
class PaymentExceptionMessageFormatter implements ExceptionMessageFormatterInterface | ||
{ | ||
/** | ||
* If the thrown exception was from a payment issue, allow the message to go through | ||
* | ||
* @param LocalizedException $e | ||
* @param string $messagePrefix | ||
* @param Field $field | ||
* @param ContextInterface $context | ||
* @param ResolveInfo $info | ||
* | ||
* @return GraphQlInputException|null | ||
*/ | ||
public function getFormatted( | ||
LocalizedException $e, | ||
string $messagePrefix, | ||
Field $field, | ||
ContextInterface $context, | ||
ResolveInfo $info | ||
): ?GraphQlInputException { | ||
if ($e instanceof PaymentException) { | ||
return new GraphQlInputException(__("$messagePrefix: %message", ['message' => $e->getMessage()]), $e); | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.