catch rendering exceptions
[grauphel.git] / controller / guicontroller.php
index 97a7f10c9289f2622b6e77eabc531ca882744583..534f18ff4bdc848130eed03feb32589dd3de6baa 100644 (file)
@@ -88,18 +88,45 @@ class GuiController extends Controller
             return new ErrorResponse('Note does not exist');
         }
 
-        $converter = new \OCA\Grauphel\Lib\Converter\Html();
+        $converter = new \OCA\Grauphel\Converter\Html();
         $converter->internalLinkHandler = array($this, 'noteLinkHandler');
+
+        try {
+            $contentHtml = $converter->convert($note->{'note-content'});
+        } catch (\OCA\Grauphel\Converter\Exception $e) {
+            $contentHtml = '<div class="error">'
+                . '<p>There was an error converting the note to HTML:</p>'
+                . '<blockquote><tt>' . htmlspecialchars($e->getMessage()) . '</tt></blockquote>'
+                . '<p>Please open a bug report at'
+                . ' <a class="lined" href="http://github.com/cweiske/grauphel/issues">'
+                . 'github.com/cweiske/grauphel/issues</a>'
+                . ' and attach the XML version of the note.'
+                . '</div>';
+        }
+
         $res->setParams(
             array(
                 'note' => $note,
-                'note-content' => $converter->convert(
-                    $note->{'note-content'}
-                ),
+                'note-content' => $contentHtml,
+                'links' => array(
+                    'json' => $this->urlGen->linkToRoute(
+                        'grauphel.api.note', array(
+                            'guid' => $guid, 'username' => $this->user->getUid()
+                        )
+                    ),
+                    'xml' => $this->urlGen->linkToRoute(
+                        'grauphel.notes.xml', array('guid' => $guid)
+                    ),
+                )
             )
         );
 
-        $this->addNavigation($res);
+        $selectedRawtag = null;
+        if (count($note->tags) > 0) {
+            $selectedRawtag = $note->tags[0];
+        }
+
+        $this->addNavigation($res, $selectedRawtag);
         return $res;
     }
 
@@ -233,6 +260,7 @@ class GuiController extends Controller
                     'href' => $this->urlGen->linkToRoute(
                         'grauphel.gui.tag', array('rawtag' => $rawtag)
                     ),
+                    'selected' => $rawtag == $selectedRawtag,
                 );
             }
         }