Added HTTP error support

This commit is contained in:
Marcin Kurczewski 2014-05-15 21:38:22 +02:00
parent aa20b81229
commit a4f7c80fe2
4 changed files with 15 additions and 11 deletions

View file

@ -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]

View file

@ -1,7 +1,10 @@
<?php
require_once '../src/core.php';
$query = rtrim($_SERVER['REQUEST_URI'], '/');
if (isset($_SERVER['REDIRECT_URL']))
$query = rtrim($_SERVER['REDIRECT_URL'], '/');
else
$query = rtrim($_SERVER['REQUEST_URI'], '/');
$context = Core::getContext();
$context->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)

View file

@ -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']);
}
}

View file

@ -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');