--- a/Controller/WikiTagController.php Mon Nov 28 15:58:34 2011 +0100
+++ b/Controller/WikiTagController.php Wed Nov 30 17:58:18 2011 +0100
@@ -193,7 +193,12 @@
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
}
// We create the new tag or get the already existing tag. $tag, $revision_id, $created
- $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);
+ try {
+ $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);
+ }
+ catch (\Exception $e){
+ return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
+ }
$tag = $ar[0];
$revision_id = $ar[1];
$created = $ar[2];
@@ -275,7 +280,13 @@
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
}
// returns array($tag, $revision_id, $created)
- $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);// tag, revision_id, created = get_or_create_tag(tag_label)
+ try {
+ $ar = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->getOrCreateTag($tag_label);
+ }
+ catch (\Exception $e){
+ return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
+ }
+
$tag = $ar[0];
$revision_id = $ar[1];
$created = $ar[2];
@@ -524,8 +535,12 @@
$id_moved_tag = $this->getRequest()->request->get('id');
$moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
// We update the tag label and its wikipedia info with the new label.
- $this->updateTagWithNewLabel($moved_tag, $tag_label);
-
+ try {
+ $this->updateTagWithNewLabel($moved_tag, $tag_label);
+ }
+ catch (\Exception $e){
+ return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
+ }
// We render the tag list.
$num_page = $this->getRequest()->request->get('num_page');
$nb_by_page = $this->getRequest()->request->get('nb_by_page');
@@ -544,7 +559,12 @@
$id_moved_tag = $this->getRequest()->request->get('tag_id');
$moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
// We update the tag label and its wikipedia info with the original label.
- return $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
+ try {
+ $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
+ }
+ catch (\Exception $e){
+ return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400);
+ }
// We render the tag list.
$num_page = $this->getRequest()->request->get('num_page');
@@ -564,7 +584,12 @@
if($label!=$tag->getLabel()){
// We get the Wikipedia informations for the sent label
$tag_label_normalized = WikiTagUtils::normalizeTag($label);
- $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
+ try {
+ $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
+ }
+ catch (\Exception $e){
+ throw new \Exception($e->getMessage());
+ }
$tag->setWikipediaInfo($wp_response);
// Save datas.
$em = $this->getDoctrine()->getEntityManager();