Skip to content

Commit

Permalink
MAGETWO-67722: Add ability to inject exception code in LocalizedExcep…
Browse files Browse the repository at this point in the history
…tion #9363

 - Expanded initial implementation
  • Loading branch information
ishakhsuvarov committed Jun 29, 2017
1 parent d902e08 commit 0f50989
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Paypal/Model/Api/ProcessableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions app/code/Magento/Store/Model/StoreIsInactiveException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 3 additions & 2 deletions lib/internal/Magento/Framework/Exception/InputException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 4 additions & 2 deletions lib/internal/Magento/Framework/Validator/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -49,7 +51,7 @@ public function __construct(
}
$phrase = new Phrase($message);
}
parent::__construct($phrase, $cause);
parent::__construct($phrase, $cause, $code);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Webapi/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0f50989

Please sign in to comment.