From 4d9cdf1beea6030622e5ecc200ca29574a1f6856 Mon Sep 17 00:00:00 2001 From: "Jagoba P. G" Date: Wed, 4 Apr 2018 13:32:10 +0200 Subject: [PATCH] Fixed error 500 when file does not exist --- .../FileBundle/Controller/DownloadController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BenGorFile/FileBundle/Controller/DownloadController.php b/src/BenGorFile/FileBundle/Controller/DownloadController.php index e50722a..74e0bd1 100644 --- a/src/BenGorFile/FileBundle/Controller/DownloadController.php +++ b/src/BenGorFile/FileBundle/Controller/DownloadController.php @@ -13,7 +13,9 @@ namespace BenGorFile\FileBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * File download controller. @@ -45,6 +47,10 @@ public function gaufretteAction($filename, $uploadDestination) */ public function symfonyAction($filename, $uploadDestination) { - return new BinaryFileResponse($uploadDestination . '/' . $filename); + try { + return new BinaryFileResponse($uploadDestination . '/' . $filename); + } catch (FileNotFoundException $exception) { + throw new NotFoundHttpException(); + } } }