From a4f7c80fe23decee70301fbc2b7d9c31c3e9c8a1 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 15 May 2014 21:38:22 +0200 Subject: [PATCH] Added HTTP error support --- public_html/.htaccess | 8 ++++---- public_html/dispatch.php | 11 ++++------- src/Controllers/StaticPagesController.php | 5 +++++ src/routes.php | 2 ++ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/public_html/.htaccess b/public_html/.htaccess index 2590a8d3..4dc8c6ec 100644 --- a/public_html/.htaccess +++ b/public_html/.htaccess @@ -1,11 +1,11 @@ DirectorySlash Off Options -Indexes -RewriteEngine On -ErrorDocument 403 /dispatch.php?request=error/http&code=403 -ErrorDocument 404 /dispatch.php?request=error/http&code=404 -ErrorDocument 500 /dispatch.php?request=error/http&code=500 +ErrorDocument 403 /fatal-error/403 +ErrorDocument 404 /fatal-error/404 +ErrorDocument 500 /fatal-error/500 +RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/thumbs/$1.thumb -f RewriteRule ^/?post/(.*)/thumb/?$ /thumbs/$1.thumb RewriteRule ^/?thumbs/(.*).thumb - [L,T=image/jpeg] diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 89c0d394..5bcfe3f2 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -1,7 +1,10 @@ query = $query; @@ -70,12 +73,6 @@ try throw new SimpleNotFoundException($query . ' not found.'); } } -catch (\Chibi\MissingViewFileException $e) -{ - $context->json = true; - $context->layoutName = 'layout-json'; - renderView(); -} catch (SimpleException $e) { if ($e instanceof SimpleNotFoundException) diff --git a/src/Controllers/StaticPagesController.php b/src/Controllers/StaticPagesController.php index 38e1cd45..990704e0 100644 --- a/src/Controllers/StaticPagesController.php +++ b/src/Controllers/StaticPagesController.php @@ -35,4 +35,9 @@ class StaticPagesController $context->path = TextHelper::absolutePath($config->help->paths[$tab]); $context->tab = $tab; } + + public function fatalErrorView($code = null) + { + throw new SimpleException('Error ' . $code . ' while retrieving ' . $_SERVER['REQUEST_URI']); + } } diff --git a/src/routes.php b/src/routes.php index d8bc281e..6111bd1b 100644 --- a/src/routes.php +++ b/src/routes.php @@ -3,6 +3,8 @@ \Chibi\Router::register(['StaticPagesController', 'mainPageView'], 'GET', '/index'); \Chibi\Router::register(['StaticPagesController', 'helpView'], 'GET', '/help'); \Chibi\Router::register(['StaticPagesController', 'helpView'], 'GET', '/help/{tab}'); +\Chibi\Router::register(['StaticPagesController', 'fatalErrorView'], 'POST', '/fatal-error/{code}'); +\Chibi\Router::register(['StaticPagesController', 'fatalErrorView'], 'GET', '/fatal-error/{code}'); \Chibi\Router::register(['AuthController', 'loginView'], 'GET', '/auth/login'); \Chibi\Router::register(['AuthController', 'loginAction'], 'POST', '/auth/login');