catch rendering exceptions
authorChristian Weiske <cweiske@cweiske.de>
Tue, 28 Oct 2014 06:40:36 +0000 (07:40 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 28 Oct 2014 06:40:36 +0000 (07:40 +0100)
controller/guicontroller.php
grauphel.css
lib/converter/exception.php [new file with mode: 0644]
lib/converter/html.php

index fc97b049a7b2bd687849ba92015b6c87604fcc47..534f18ff4bdc848130eed03feb32589dd3de6baa 100644 (file)
@@ -88,14 +88,26 @@ 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(
index 571e5800fc93a9a9fcf84a9451cf6d8b85ff55dd..0cddce6fe6b165daa868e30f906ecbb26160c919 100644 (file)
@@ -35,6 +35,9 @@
     padding: 1ex;
     font-family: monospace;
 }
+.app-grauphel #app-content blockquote {
+    margin-left: 2ex;
+}
 
 .app-grauphel #app-content ul {
     list-style-type: disc;
@@ -53,6 +56,9 @@
 .app-grauphel #app-content .success {
     color: green;
 }
+.app-grauphel #app-content .error a {
+    color: red !important;
+}
 
 .app-grauphel #app-content .actions {
     float: right;
diff --git a/lib/converter/exception.php b/lib/converter/exception.php
new file mode 100644 (file)
index 0000000..ef236a6
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Part of grauphel
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Grauphel
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/grauphel.htm
+ */
+namespace OCA\Grauphel\Converter;
+
+/**
+ * Something went wrong during conversion
+ *
+ * @category  Tools
+ * @package   Grauphel
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version   Release: @package_version@
+ * @link      http://cweiske.de/grauphel.htm
+ */
+class Exception extends \Exception
+{
+}
+?>
index 1723a5b0f4d6dc48f91a5ac34c8d9d7c12a45a81..eeb2b665c594dcf7130a15b5275a79269eebb38e 100644 (file)
@@ -11,7 +11,7 @@
  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
  * @link      http://cweiske.de/grauphel.htm
  */
-namespace OCA\Grauphel\Lib\Converter;
+namespace OCA\Grauphel\Converter;
 use \XMLReader;
 
 /**
@@ -121,7 +121,7 @@ class Html
                 $store .= nl2br(htmlspecialchars($reader->value));
                 break;
             default:
-                throw new \Exception(
+                throw new Exception(
                     'Unsupported XML node type: ' . $reader->nodeType
                 );
             }