Skip to content

Commit

Permalink
Merge pull request #8 from jagoPG/update/download-file-exception
Browse files Browse the repository at this point in the history
Fixed error 500 when file does not exist
  • Loading branch information
benatespina authored Apr 4, 2018
2 parents 7116f3a + 4d9cdf1 commit 881d5ab
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/BenGorFile/FileBundle/Controller/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 881d5ab

Please sign in to comment.