Permalink
Browse files

Replace NotFoundHttpException with NotLoadableException

  • Loading branch information...
1 parent be933eb commit 19c2f82e550366262cd2915b9d1643f6ce17bcce Iakov Mishchenko committed Apr 23, 2014
@@ -3,7 +3,7 @@
namespace Liip\ImagineBundle\Binary\Loader;
use Doctrine\Common\Persistence\ObjectManager;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
abstract class AbstractDoctrineLoader implements LoaderInterface
{
@@ -64,7 +64,7 @@ public function find($path)
}
if (!$image) {
- throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $path));
+ throw new NotLoadableException(sprintf('Source image not found with id "%s"', $path));
}
return stream_get_contents($this->getStreamFromImage($image));
@@ -2,11 +2,12 @@
namespace Liip\ImagineBundle\Binary\Loader;
+
use Liip\ImagineBundle\Model\Binary;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesserInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
class FileSystemLoader implements LoaderInterface
{
@@ -47,13 +48,13 @@ public function __construct(
public function find($path)
{
if (false !== strpos($path, '../')) {
- throw new NotFoundHttpException(sprintf("Source image was searched with '%s' out side of the defined root path", $path));
+ throw new NotLoadableException(sprintf("Source image was searched with '%s' out side of the defined root path", $path));
}
$absolutePath = $this->rootPath.'/'.ltrim($path, '/');
if (false == file_exists($absolutePath)) {
- throw new NotFoundHttpException(sprintf('Source image not found in "%s"', $absolutePath));
+ throw new NotLoadableException(sprintf('Source image not found in "%s"', $absolutePath));
}
$mimeType = $this->mimeTypeGuesser->guess($absolutePath);
@@ -3,7 +3,7 @@
namespace Liip\ImagineBundle\Binary\Loader;
use Doctrine\ODM\MongoDB\DocumentManager;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
class GridFSLoader implements LoaderInterface
{
@@ -37,7 +37,7 @@ public function find($id)
->find(new \MongoId($id));
if (!$image) {
- throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $id));
+ throw new NotLoadableException(sprintf('Source image not found with id "%s"', $id));
}
return $image['file']->getBytes();
@@ -6,10 +6,12 @@
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
+use Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\UriSigner;
class ImagineController
@@ -79,7 +81,12 @@ public function filterAction(Request $request, $path, $filter)
}
if (!$this->cacheManager->isStored($path, $filter)) {
- $binary = $this->dataManager->find($filter, $path);
+ try {
+ $binary = $this->dataManager->find($filter, $path);
+ } catch (NotLoadableException $e) {
+
+ throw new NotFoundHttpException('Source image could not be found', $e);
+ }
$this->cacheManager->store(
$this->filterManager->applyFilter($binary, $filter, $runtimeConfig),
@@ -0,0 +1,10 @@
+<?php
+
+namespace Liip\ImagineBundle\Exception\Binary\Loader;
+
+use Liip\ImagineBundle\Exception\ExceptionInterface;
+
+class NotLoadableException extends \RuntimeException implements ExceptionInterface
+{
+
+}
@@ -50,7 +50,7 @@ public function testThrowExceptionIfPathHasDoublePointSlashAtBegging()
);
$this->setExpectedException(
- 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException',
+ 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException',
'Source image was searched with'
);
@@ -66,7 +66,7 @@ public function testThrowExceptionIfPathHasDoublePointSlashInTheMiddle()
);
$this->setExpectedException(
- 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException',
+ 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException',
'Source image was searched with'
);
@@ -82,7 +82,7 @@ public function testThrowExceptionIfFileNotExist()
);
$this->setExpectedException(
- 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException',
+ 'Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException',
'Source image not found'
);
@@ -94,6 +94,15 @@ public function testThrowBadRequestIfSignInvalidWhileUsingCustomFilters()
)));
}
+ /**
+ * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+ * @expectedExceptionMessage Source image could not be found
+ */
+ public function testShouldThrowNotFoundHttpExceptionIfFileNotExists()
+ {
+ $this->client->request('GET', '/media/cache/thumbnail_web_path/images/shrodinger_cats_which_not_exist.jpeg');
+ }
+
public function testShouldResolveWithCustomFiltersPopulatingCacheFirst()
{
/** @var UriSigner $uriSigner */

0 comments on commit 19c2f82

Please sign in to comment.