From 0f50989ad7462c27565c99a05d08c831f3f17bda Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Thu, 29 Jun 2017 17:19:11 +0300 Subject: [PATCH] MAGETWO-67722: Add ability to inject exception code in LocalizedException #9363 - Expanded initial implementation --- app/code/Magento/Paypal/Model/Api/ProcessableException.php | 2 +- .../Magento/Search/Model/Synonym/MergeConflictException.php | 5 +++-- app/code/Magento/Store/Model/StoreIsInactiveException.php | 5 +++-- .../Framework/Exception/AbstractAggregateException.php | 5 +++-- .../Magento/Framework/Exception/AlreadyExistsException.php | 5 +++-- lib/internal/Magento/Framework/Exception/InputException.php | 5 +++-- .../Magento/Framework/Exception/NoSuchEntityException.php | 5 +++-- .../Magento/Framework/Exception/SerializationException.php | 5 +++-- .../Exception/TemporaryState/CouldNotSaveException.php | 2 +- lib/internal/Magento/Framework/Validator/Exception.php | 6 ++++-- lib/internal/Magento/Framework/Webapi/Exception.php | 2 +- 11 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Api/ProcessableException.php b/app/code/Magento/Paypal/Model/Api/ProcessableException.php index e455cf3128428..71225cf8cb3f3 100644 --- a/app/code/Magento/Paypal/Model/Api/ProcessableException.php +++ b/app/code/Magento/Paypal/Model/Api/ProcessableException.php @@ -40,7 +40,7 @@ class ProcessableException extends LocalizedException */ public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0) { - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); $this->code = $code; } diff --git a/app/code/Magento/Search/Model/Synonym/MergeConflictException.php b/app/code/Magento/Search/Model/Synonym/MergeConflictException.php index 2c0ab409b47c5..34b1af0bf949c 100644 --- a/app/code/Magento/Search/Model/Synonym/MergeConflictException.php +++ b/app/code/Magento/Search/Model/Synonym/MergeConflictException.php @@ -28,10 +28,11 @@ class MergeConflictException extends LocalizedException * @param array $conflictingSynonyms * @param Phrase|null $phrase * @param \Exception|null $cause + * @param int $code */ - public function __construct(array $conflictingSynonyms, Phrase $phrase = null, \Exception $cause = null) + public function __construct(array $conflictingSynonyms, Phrase $phrase = null, \Exception $cause = null, $code = 0) { - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); $this->conflictingSynonyms = $conflictingSynonyms; } diff --git a/app/code/Magento/Store/Model/StoreIsInactiveException.php b/app/code/Magento/Store/Model/StoreIsInactiveException.php index 00293e9c45013..545fb0e9d81b7 100644 --- a/app/code/Magento/Store/Model/StoreIsInactiveException.php +++ b/app/code/Magento/Store/Model/StoreIsInactiveException.php @@ -16,12 +16,13 @@ class StoreIsInactiveException extends LocalizedException /** * @param \Magento\Framework\Phrase $phrase * @param \Exception $cause + * @param int $code */ - public function __construct(Phrase $phrase = null, \Exception $cause = null) + public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0) { if ($phrase === null) { $phrase = new Phrase('Store is inactive'); } - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } } diff --git a/lib/internal/Magento/Framework/Exception/AbstractAggregateException.php b/lib/internal/Magento/Framework/Exception/AbstractAggregateException.php index 14e711429827c..56c3bd285bc1e 100644 --- a/lib/internal/Magento/Framework/Exception/AbstractAggregateException.php +++ b/lib/internal/Magento/Framework/Exception/AbstractAggregateException.php @@ -39,11 +39,12 @@ abstract class AbstractAggregateException extends LocalizedException * * @param \Magento\Framework\Phrase $phrase * @param \Exception $cause + * @param int $code */ - public function __construct(Phrase $phrase, \Exception $cause = null) + public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0) { $this->originalPhrase = $phrase; - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } /** diff --git a/lib/internal/Magento/Framework/Exception/AlreadyExistsException.php b/lib/internal/Magento/Framework/Exception/AlreadyExistsException.php index 1917385148031..cc1206623a2fb 100644 --- a/lib/internal/Magento/Framework/Exception/AlreadyExistsException.php +++ b/lib/internal/Magento/Framework/Exception/AlreadyExistsException.php @@ -15,12 +15,13 @@ class AlreadyExistsException extends LocalizedException /** * @param Phrase $phrase * @param \Exception $cause + * @param int $code */ - public function __construct(Phrase $phrase = null, \Exception $cause = null) + public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0) { if ($phrase === null) { $phrase = new Phrase('Unique constraint violation found'); } - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } } diff --git a/lib/internal/Magento/Framework/Exception/InputException.php b/lib/internal/Magento/Framework/Exception/InputException.php index 2dc3033be1da5..2496326681e7b 100644 --- a/lib/internal/Magento/Framework/Exception/InputException.php +++ b/lib/internal/Magento/Framework/Exception/InputException.php @@ -49,13 +49,14 @@ class InputException extends AbstractAggregateException * * @param \Magento\Framework\Phrase $phrase * @param \Exception $cause + * @param int $code */ - public function __construct(Phrase $phrase = null, \Exception $cause = null) + public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0) { if ($phrase === null) { $phrase = new Phrase('One or more input exceptions have occurred.'); } - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } /** diff --git a/lib/internal/Magento/Framework/Exception/NoSuchEntityException.php b/lib/internal/Magento/Framework/Exception/NoSuchEntityException.php index 6e160c6ec6da2..42b30d45e4c72 100644 --- a/lib/internal/Magento/Framework/Exception/NoSuchEntityException.php +++ b/lib/internal/Magento/Framework/Exception/NoSuchEntityException.php @@ -27,13 +27,14 @@ class NoSuchEntityException extends LocalizedException /** * @param \Magento\Framework\Phrase $phrase * @param \Exception $cause + * @param int $code */ - public function __construct(Phrase $phrase = null, \Exception $cause = null) + public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0) { if ($phrase === null) { $phrase = new Phrase('No such entity.'); } - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } /** diff --git a/lib/internal/Magento/Framework/Exception/SerializationException.php b/lib/internal/Magento/Framework/Exception/SerializationException.php index 5346425a9b545..27d0bc0c4371a 100644 --- a/lib/internal/Magento/Framework/Exception/SerializationException.php +++ b/lib/internal/Magento/Framework/Exception/SerializationException.php @@ -27,12 +27,13 @@ class SerializationException extends LocalizedException /** * @param \Magento\Framework\Phrase $phrase * @param \Exception $cause + * @param int $code */ - public function __construct(Phrase $phrase = null, \Exception $cause = null) + public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0) { if ($phrase === null) { $phrase = new Phrase('One or more input exceptions have occurred.'); } - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } } diff --git a/lib/internal/Magento/Framework/Exception/TemporaryState/CouldNotSaveException.php b/lib/internal/Magento/Framework/Exception/TemporaryState/CouldNotSaveException.php index d8ce8dee035db..807bb2d31a498 100644 --- a/lib/internal/Magento/Framework/Exception/TemporaryState/CouldNotSaveException.php +++ b/lib/internal/Magento/Framework/Exception/TemporaryState/CouldNotSaveException.php @@ -25,7 +25,7 @@ class CouldNotSaveException extends LocalizedCouldNotSaveException implements Te */ public function __construct(Phrase $phrase, \Exception $previous = null, $code = 0) { - parent::__construct($phrase, $previous); + parent::__construct($phrase, $previous, $code); $this->code = $code; } } diff --git a/lib/internal/Magento/Framework/Validator/Exception.php b/lib/internal/Magento/Framework/Validator/Exception.php index 0e245b2a4a7e9..c70ecfabb52af 100644 --- a/lib/internal/Magento/Framework/Validator/Exception.php +++ b/lib/internal/Magento/Framework/Validator/Exception.php @@ -30,11 +30,13 @@ class Exception extends InputException * @param \Magento\Framework\Phrase $phrase * @param \Exception $cause * @param array $messages Validation error messages + * @param int $code */ public function __construct( Phrase $phrase = null, \Exception $cause = null, - array $messages = [] + array $messages = [], + $code = 0 ) { if (!empty($messages)) { $message = ''; @@ -49,7 +51,7 @@ public function __construct( } $phrase = new Phrase($message); } - parent::__construct($phrase, $cause); + parent::__construct($phrase, $cause, $code); } /** diff --git a/lib/internal/Magento/Framework/Webapi/Exception.php b/lib/internal/Magento/Framework/Webapi/Exception.php index 01a9848c63282..97ebbc40865ab 100644 --- a/lib/internal/Magento/Framework/Webapi/Exception.php +++ b/lib/internal/Magento/Framework/Webapi/Exception.php @@ -105,7 +105,7 @@ public function __construct( if ($httpCode < 400 || $httpCode > 599) { throw new \InvalidArgumentException(sprintf('The specified HTTP code "%d" is invalid.', $httpCode)); } - parent::__construct($phrase); + parent::__construct($phrase, null, $code); $this->code = $code; $this->_httpCode = $httpCode; $this->_details = $details;