From f2ca72dcb3717ca62212924dc9c642524806c0ef Mon Sep 17 00:00:00 2001
From: Christoph Burschka <christoph.burschka@pwc-digital.ch>
Date: Mon, 23 Jan 2017 08:51:12 +0100
Subject: [PATCH] Issue #2845221: Catch rendering exceptions in controller.

---
 src/Controller/EntityPrintController.php | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/Controller/EntityPrintController.php b/src/Controller/EntityPrintController.php
index d4eb6c9..adcb8eb 100644
--- a/src/Controller/EntityPrintController.php
+++ b/src/Controller/EntityPrintController.php
@@ -77,6 +77,10 @@ class EntityPrintController extends ControllerBase {
 
     try {
       $pdf_engine = $this->pluginManager->createInstance($config->get('pdf_engine'));
+      return (new StreamedResponse(function() use ($entity, $pdf_engine, $config) {
+        // The PDF is sent straight to the browser.
+        $this->pdfBuilder->getEntityRenderedAsPdf($entity, $pdf_engine, $config->get('force_download'), $config->get('default_css'));
+      }))->send();
     }
     catch (PdfEngineException $e) {
       // Build a safe markup string using Xss::filter() so that the instructions
@@ -85,11 +89,6 @@ class EntityPrintController extends ControllerBase {
 
       return new RedirectResponse($entity->toUrl()->toString());
     }
-
-    return (new StreamedResponse(function() use ($entity, $pdf_engine, $config) {
-      // The PDF is sent straight to the browser.
-      $this->pdfBuilder->getEntityRenderedAsPdf($entity, $pdf_engine, $config->get('force_download'), $config->get('default_css'));
-    }))->send();
   }
 
   /**
-- 
2.10.1 (Apple Git-78)

