0

I have a small script that create a new Customer in Magento 2 and used to work but sudenly, it does not.

I included a try...catch but do not know how to show the error message in console. I want to be able to return the error phare:

try {

        $this->_customerRepository->save($this->_customerObject);
        $this->answer = array('response' => true);

    } catch (\Magento\Framework\Exception\State\InputMismatchException $ex) {
        $this->answer = array('response' => 'Email exists');
    } catch (\Magento\Framework\Exception\InputException $ex) {
        $this->answer = array('response' => 'bad input', 'ex' => $ex->getErrors());
    } catch (\Magento\Framework\Exception\LocalizedException $ex) {
        $this->answer = array('response' => 'No idea....');
    }

The Exception arised is InputException, and want to return the phrase in the response, because i do not know where is the fault.

getErrors() only return an object and can not see the error message in console.

What should I do?

1 Answer 1

0

getErrors() returns an array of LocalizedException: https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Exception/AbstractAggregateException.php#L90

To get the actual message you shoul call getRawMessage(): https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Exception/LocalizedException.php#L42

this should return a helpfull message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.