From: Christian Weiske Date: Tue, 28 Oct 2014 06:40:36 +0000 (+0100) Subject: catch rendering exceptions X-Git-Tag: v0.4.0~6 X-Git-Url: https://git.cweiske.de/grauphel.git/commitdiff_plain/272bb16b2d434090008d0759e10ff28bab96cb51?hp=0c9b45d210a5d94b3ba219e32b73233a5a795f61 catch rendering exceptions --- diff --git a/controller/guicontroller.php b/controller/guicontroller.php index fc97b04..534f18f 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -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 = '
' + . '

There was an error converting the note to HTML:

' + . '
' . htmlspecialchars($e->getMessage()) . '
' + . '

Please open a bug report at' + . ' ' + . 'github.com/cweiske/grauphel/issues' + . ' and attach the XML version of the note.' + . '

'; + } + $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( diff --git a/grauphel.css b/grauphel.css index 571e580..0cddce6 100644 --- a/grauphel.css +++ b/grauphel.css @@ -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 index 0000000..ef236a6 --- /dev/null +++ b/lib/converter/exception.php @@ -0,0 +1,30 @@ + + * @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 + * @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 +{ +} +?> diff --git a/lib/converter/html.php b/lib/converter/html.php index 1723a5b..eeb2b66 100644 --- a/lib/converter/html.php +++ b/lib/converter/html.php @@ -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 ); }