Hi,

I'm playing with the Symfony2 sandbox and MongoDB.


I can save a mongo document using
$dm->flush(array('safe' => true));

and I get a MongoCursorException when one of the index keys is
duplicated in the database, but I would like to catch that exception in
the controller to tweak the response: maybe set a flash message, or a
redirect, or whatever when the document could'n be saved.


How can I do this?
I don't see any example like this in the documentation, and I tried a
try {} catch {} but it doesn't work.


Thanks!


PD: here, a code snippet of my controller (action):



$user = new User();
$user->setUsername($username);
$user->setEmail($email);
$user->setPassword($password);

// Load Doctrine ODM
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$dm->persist($user);

// Flush in "safe" mode to enforce an Exception if keys are not unique
try {
$dm->flush(array('safe' => true));
} catch (MongoCursorException $e) {
throw new NotFoundHttpException('Just a 404 error, not what I want.
Anyway, it doesn't work.');
}

return $this->redirect($this->generateUrl('user_index'));

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to