Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ValidationException Class Reference
Inheritance diagram for ValidationException:
LocalizedException AggregateExceptionInterface

Public Member Functions

 __construct (Phrase $phrase, \Exception $cause=null, $code=0, ValidationResult $validationResult=null)
 
 getErrors ()
 
- Public Member Functions inherited from LocalizedException
 __construct (Phrase $phrase, \Exception $cause=null, $code=0)
 
 getRawMessage ()
 
 getParameters ()
 
 getLogMessage ()
 

Additional Inherited Members

- Protected Attributes inherited from LocalizedException
 $phrase
 
 $logMessage
 

Detailed Description

Validation exception with possibility to set several error messages

ValidationException exists to be compatible with the Web-API (SOAP and REST) implementation which currently uses Magento\Framework\Exception\AggregateExceptionInterface returned as a result of ServiceContracts call to support Multi-Error response.

@api

Definition at line 21 of file ValidationException.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Phrase  $phrase,
\Exception  $cause = null,
  $code = 0,
ValidationResult  $validationResult = null 
)
Parameters
Phrase$phrase
\Exception$cause
int$code
ValidationResult | null$validationResult

Definition at line 34 of file ValidationException.php.

39  {
40  parent::__construct($phrase, $cause, $code);
41  $this->validationResult = $validationResult;
42  }
$code
Definition: info.phtml:12

Member Function Documentation

◆ getErrors()

getErrors ( )

Returns LocalizedException[] array to be compatible with current Implementation in Web API which relies on this behavior

See also
the \Magento\Framework\Webapi\Exception which receives $errors as a set of Localized Exceptions
Returns
LocalizedException[]

Implements AggregateExceptionInterface.

Definition at line 47 of file ValidationException.php.

47  : array
48  {
49  $localizedErrors = [];
50  if (null !== $this->validationResult) {
51  foreach ($this->validationResult->getErrors() as $error) {
52  $localizedErrors[] = new LocalizedException($error);
53  }
54  }
55  return $localizedErrors;
56  }

The documentation for this class was generated from the following file: