diff --git a/framework/core/src/Foundation/ErrorHandling/ViewRenderer.php b/framework/core/src/Foundation/ErrorHandling/ViewRenderer.php index 4ac50ffd7..438a2d9d6 100644 --- a/framework/core/src/Foundation/ErrorHandling/ViewRenderer.php +++ b/framework/core/src/Foundation/ErrorHandling/ViewRenderer.php @@ -51,26 +51,29 @@ class ViewRenderer implements Formatter return new HtmlResponse($view->render(), $error->getStatusCode()); } + const ERRORS_WITH_VIEWS = ['csrf_token_mismatch', 'not_found']; + private function determineView(HandledError $error): string { - $view = [ - 'route_not_found' => '404', - 'csrf_token_mismatch' => '419', - ][$error->getType()] ?? 'default'; + $type = $error->getType(); - return "flarum.forum::error.$view"; + if (in_array($type, self::ERRORS_WITH_VIEWS)) { + return "flarum.forum::error.$type"; + } else { + return 'flarum.forum::error.default'; + } } private function getMessage(HandledError $error) { - return $this->getTranslationIfExists($error->getStatusCode()) + return $this->getTranslationIfExists($error->getType()) ?? $this->getTranslationIfExists('unknown') ?? 'An error occurred while trying to load this page.'; } private function getTranslationIfExists(string $errorType) { - $key = "core.views.error.${errorType}_message"; + $key = "core.views.error.$errorType"; $translation = $this->translator->trans($key, ['{forum}' => $this->settings->get('forum_title')]); return $translation === $key ? null : $translation; diff --git a/framework/core/src/Foundation/ErrorServiceProvider.php b/framework/core/src/Foundation/ErrorServiceProvider.php index ec82370ee..aa7060bb5 100644 --- a/framework/core/src/Foundation/ErrorServiceProvider.php +++ b/framework/core/src/Foundation/ErrorServiceProvider.php @@ -38,8 +38,7 @@ class ErrorServiceProvider extends AbstractServiceProvider 'permission_denied' => 403, // 404 Not Found - 'model_not_found' => 404, - 'route_not_found' => 404, + 'not_found' => 404, // 405 Method Not Allowed 'method_not_allowed' => 405, @@ -52,7 +51,7 @@ class ErrorServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.error.classes', function () { return [ InvalidParameterException::class => 'invalid_parameter', - ModelNotFoundException::class => 'model_not_found', + ModelNotFoundException::class => 'not_found', ]; }); diff --git a/framework/core/src/Http/Exception/RouteNotFoundException.php b/framework/core/src/Http/Exception/RouteNotFoundException.php index 820da488e..183742585 100644 --- a/framework/core/src/Http/Exception/RouteNotFoundException.php +++ b/framework/core/src/Http/Exception/RouteNotFoundException.php @@ -18,6 +18,6 @@ class RouteNotFoundException extends Exception implements KnownError { public function getType(): string { - return 'route_not_found'; + return 'not_found'; } } diff --git a/framework/core/views/error/419.blade.php b/framework/core/views/error/csrf_token_mismatch.blade.php similarity index 66% rename from framework/core/views/error/419.blade.php rename to framework/core/views/error/csrf_token_mismatch.blade.php index 63c5fb4be..9673c6763 100644 --- a/framework/core/views/error/419.blade.php +++ b/framework/core/views/error/csrf_token_mismatch.blade.php @@ -6,7 +6,7 @@

- {{ $translator->trans('core.views.error.419_return_link') }} + {{ $translator->trans('core.views.error.csrf_token_mismatch_return_link') }}

@endsection diff --git a/framework/core/views/error/404.blade.php b/framework/core/views/error/not_found.blade.php similarity index 57% rename from framework/core/views/error/404.blade.php rename to framework/core/views/error/not_found.blade.php index 928b4a8a3..557bc3cb9 100644 --- a/framework/core/views/error/404.blade.php +++ b/framework/core/views/error/not_found.blade.php @@ -6,7 +6,7 @@

- {{ $translator->trans('core.views.error.404_return_link', ['{forum}' => $settings->get('forum_title')]) }} + {{ $translator->trans('core.views.error.not_found_return_link', ['{forum}' => $settings->get('forum_title')]) }}

@endsection