Skip to content

Commit

Permalink
[5.x] Improve ImageGenerator Exception handling (#10786)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
indykoning and jasonvarga authored Sep 11, 2024
1 parent 5ca20e2 commit 121607d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Http/Controllers/CP/Assets/ThumbnailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Statamic\Http\Controllers\CP\Assets;

use Illuminate\Support\Facades\Cache;
use League\Flysystem\UnableToReadFile;
use League\Glide\Server;
use Statamic\Exceptions\NotFoundHttpException;
use Statamic\Facades\Asset;
use Statamic\Facades\Config;
use Statamic\Facades\Image;
Expand Down Expand Up @@ -110,6 +112,8 @@ private function generate()
$this->asset,
$preset ? ['p' => $preset] : []
);
} catch (UnableToReadFile $e) {
throw new NotFoundHttpException;
} finally {
Cache::forget($this->mutex());
}
Expand Down
3 changes: 1 addition & 2 deletions src/Imaging/ImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use League\Glide\Server;
use Statamic\Contracts\Assets\Asset;
use Statamic\Events\GlideImageGenerated;
use Statamic\Exceptions\NotFoundHttpException;
use Statamic\Facades\Asset as Assets;
use Statamic\Facades\Config;
use Statamic\Facades\File;
Expand Down Expand Up @@ -258,7 +257,7 @@ private function generate($image)
try {
$path = $this->server->makeImage($image, $this->params);
} catch (GlideFileNotFoundException $e) {
throw new NotFoundHttpException;
throw UnableToReadFile::fromLocation($image);
}

GlideImageGenerated::dispatch($path, $this->params);
Expand Down

0 comments on commit 121607d

Please sign in to comment.