commit 5aa2161d5fa26b6f453b1ebda5ddb282829c69e1
parent c88db5870730916af4d1438691ce681c9c3b551b
Author: Felicitus <felicitus@felicitus.org>
Date: Sat, 28 Nov 2015 14:09:03 +0100
Catch the file not found exception and display a 404 error. Also log the issue to the log file. Fixes #503
Diffstat:
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/PartKeepr/UploadedFileBundle/Controller/FileController.php b/src/PartKeepr/UploadedFileBundle/Controller/FileController.php
@@ -2,7 +2,7 @@
namespace PartKeepr\UploadedFileBundle\Controller;
use Doctrine\ORM\EntityManager;
-use Gaufrette\Filesystem;
+use Gaufrette\Exception\FileNotFound;
use PartKeepr\UploadedFileBundle\Entity\UploadedFile;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
@@ -54,11 +54,23 @@ abstract class FileController extends Controller
$storage = $this->get("partkeepr_uploadedfile_service")->getStorage($file);
- return new Response(
- $storage->read($file->getFullFilename()),
- 200,
- array("Content-Type" => $file->getMimeType())
- );
+ try {
+ return new Response(
+ $storage->read($file->getFullFilename()),
+ 200,
+ array("Content-Type" => $file->getMimeType())
+ );
+ } catch (FileNotFound $e) {
+ $this->get("logger")->addError(sprintf("File %s not found in storage %s", $file->getFilename(),
+ $file->getType()));
+
+ return new Response(
+ "404 File not found",
+ 404
+ );
+ }
+
+
}
/**