diff --git a/formwork/src/Controllers/AssetsController.php b/formwork/src/Controllers/AssetsController.php index 958f03c26..14833915f 100644 --- a/formwork/src/Controllers/AssetsController.php +++ b/formwork/src/Controllers/AssetsController.php @@ -3,34 +3,34 @@ namespace Formwork\Controllers; use Formwork\Http\FileResponse; +use Formwork\Http\Response; use Formwork\Router\RouteParams; -use Formwork\Utils\Exceptions\FileNotFoundException; use Formwork\Utils\FileSystem; class AssetsController extends AbstractController { - public function asset(RouteParams $routeParams): FileResponse + public function asset(RouteParams $routeParams): Response { $path = FileSystem::joinPaths($this->config->get('system.images.processPath'), $routeParams->get('id'), $routeParams->get('name')); - if (FileSystem::isFile($path)) { + if (FileSystem::isFile($path, assertExists: false)) { return new FileResponse($path, headers: ['Cache-Control' => 'private, max-age=31536000, immutable'], autoEtag: true, autoLastModified: true); } - throw new FileNotFoundException('Cannot find asset'); + return $this->forward(PageController::class, 'error'); } - public function template(RouteParams $routeParams): FileResponse + public function template(RouteParams $routeParams): Response { $path = FileSystem::joinPaths($this->config->get('system.templates.path'), 'assets', $routeParams->get('file')); - if (FileSystem::isFile($path)) { + if (FileSystem::isFile($path, assertExists: false)) { $headers = $this->request->query()->has('v') ? ['Cache-Control' => 'private, max-age=31536000, immutable'] : []; return new FileResponse($path, headers: $headers, autoEtag: true, autoLastModified: true); } - throw new FileNotFoundException('Cannot find asset'); + return $this->forward(PageController::class, 'error'); } } diff --git a/formwork/src/Controllers/PageController.php b/formwork/src/Controllers/PageController.php index 777ba7fa9..3f35bc62f 100644 --- a/formwork/src/Controllers/PageController.php +++ b/formwork/src/Controllers/PageController.php @@ -97,6 +97,11 @@ public function load(RouteParams $routeParams, Statistics $statistics): Response return $this->getPageResponse($this->site->errorPage()); } + public function error(): Response + { + return $this->getPageResponse($this->site->errorPage()); + } + protected function getPageResponse(Page $page): Response { if ($this->site->currentPage() === null) { diff --git a/formwork/src/Panel/Controllers/AssetsController.php b/formwork/src/Panel/Controllers/AssetsController.php index 32d4f5860..59434e632 100644 --- a/formwork/src/Panel/Controllers/AssetsController.php +++ b/formwork/src/Panel/Controllers/AssetsController.php @@ -3,23 +3,23 @@ namespace Formwork\Panel\Controllers; use Formwork\Http\FileResponse; +use Formwork\Http\Response; use Formwork\Router\RouteParams; -use Formwork\Utils\Exceptions\FileNotFoundException; use Formwork\Utils\FileSystem; class AssetsController extends AbstractController { - public function asset(RouteParams $routeParams): FileResponse + public function asset(RouteParams $routeParams): Response { $path = FileSystem::joinPaths($this->config->get('system.panel.paths.assets'), $routeParams->get('type'), $routeParams->get('file')); - if (FileSystem::isFile($path)) { + if (FileSystem::isFile($path, assertExists: false)) { $headers = ($this->request->query()->has('v') || $routeParams->get('type') === 'icons') ? ['Cache-Control' => 'private, max-age=31536000, immutable'] : []; return new FileResponse($path, headers: $headers, autoEtag: true, autoLastModified: true); } - throw new FileNotFoundException('Cannot find asset'); + return $this->forward(ErrorsController::class, 'notFound'); } } diff --git a/formwork/src/Panel/Controllers/UsersController.php b/formwork/src/Panel/Controllers/UsersController.php index dbb536d25..ce368b4a2 100644 --- a/formwork/src/Panel/Controllers/UsersController.php +++ b/formwork/src/Panel/Controllers/UsersController.php @@ -17,7 +17,6 @@ use Formwork\Router\RouteParams; use Formwork\Users\User; use Formwork\Utils\Arr; -use Formwork\Utils\Exceptions\FileNotFoundException; use Formwork\Utils\FileSystem; class UsersController extends AbstractController @@ -217,11 +216,11 @@ public function images(RouteParams $routeParams): Response { $path = FileSystem::joinPaths($this->config->get('system.users.paths.images'), $routeParams->get('image')); - if (FileSystem::isFile($path)) { + if (FileSystem::isFile($path, assertExists: false)) { return new FileResponse($path, headers: ['Cache-Control' => 'private, max-age=31536000, immutable'], autoEtag: true, autoLastModified: true); } - throw new FileNotFoundException('Cannot find asset'); + return $this->forward(ErrorsController::class, 'notFound'); } /**