[FLOW3-general] How can i catch TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException in controllerAction

mosaiq_marcel mosaiq_marcel at web.de
Thu May 3 18:57:48 CEST 2012


Hi,
when i try to create a user with a given invalid email adress 
(me at xyz.tld) i got the following error:

#1322585164: An instance of "TYPO3\Party\Domain\Model\Person" failed to 
pass validation with 1 error(s): primaryElectronicAddress: Please 
specify a valid email address. (More information)

TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException thrown 
in file
D:\Localweb\htdocs\mfg.local\Data\Temporary\Development\Cache\Code\FLOW3_Object_Classes\TYPO3_FLOW3_Persistence_Doctrine_PersistenceManager_Original.php 
in line 106.
Reference code: 20120503181305d6723e

So i would like to catch this exception within my creatAction, but this 
doesn't work:

public function createAction() {
     $arguments = $this->request->getArguments();
     try {
	$account = 
$this->accountFactory->createAccountWithPassword($arguments['name'], 
$arguments['pass'], array($arguments['role']), 
$this->authenticationProviderName);
	$this->accountRepository->add($account);			
	$personName = new \TYPO3\Party\Domain\Model\PersonName('', '', '', 
$arguments['name']);
	$electronicAddress = new \TYPO3\Party\Domain\Model\ElectronicAddress();
	$electronicAddress->setIdentifier($arguments['email']);
	$electronicAddress->setType($electronicAddress::TYPE_EMAIL);
	$electronicAddress->setUsage($electronicAddress::USAGE_WORK);
	$person = new \TYPO3\Party\Domain\Model\Person();
	$person->setName($personName);	
	$person->setPrimaryElectronicAddress($electronicAddress);
	$person->addAccount($account);
	$this->partyRepository->add($person);
     }catch 
(\TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException $e) {
         echo $e->getMessage()."<br>";
     }
     $this->redirect('index');
}

How can i catch this exception to give back a user friendly error 
message? Or how can i deactivate this validation?

Best regards,
Marcel


More information about the FLOW3-general mailing list