Added error handler

This commit is contained in:
2017-09-07 16:11:54 +07:00
parent 796148a532
commit 23622bc5a8
14 changed files with 204 additions and 56 deletions

View File

@@ -7,5 +7,7 @@ class Config
DB_HOST = 'mariadb',
DB_DB = 'lepisi',
DB_UNAME = 'root',
DB_PWD = 'root';
DB_PWD = 'root',
LOG_ERRORS = false;
}

View File

@@ -24,6 +24,7 @@ class Home
public function login()
{
if (Session::exists('userid')) {
Session::flash('info', 'You already logged in');
Redirect::to('/');
} else {
View::render('Access/login.html', [
@@ -39,7 +40,7 @@ class Home
'token' => Token::generate()
]);
} else {
Redirect::to('/');
throw new \Exception("Bad Request", 400);
}
}

View File

@@ -30,7 +30,7 @@ class Posts
['valid_at', '<=', $now],
['status', '!=', 3]
]);
if ($valid !== false) {
if ($valid) {
foreach ($valid as $fields) {
$id = $fields['id'];
@@ -42,7 +42,7 @@ class Posts
['valid_at', '>', $now],
['status', '!=', 3]
]);
if ($not_valid !== false) {
if ($not_valid) {
foreach ($not_valid as $fields) {
$id = $fields['id'];
@@ -54,7 +54,7 @@ class Posts
['expired_at', '<', $now],
['status', '!=', 3]
]);
if ($expired !== false) {
if ($expired) {
foreach ($expired as $fields) {
$id = $fields['id'];
@@ -108,7 +108,7 @@ class Posts
'token' => Token::generate()
]);
} else {
Redirect::to('/');
throw new \Exception("Page not found", 404);
}
}
@@ -148,7 +148,7 @@ class Posts
);
}
} else {
Redirect::to('/');
throw new \Exception("Page not found", 404);
}
}
@@ -162,7 +162,7 @@ class Posts
'token' => Token::generate()
]);
} else {
Redirect::to('/');
throw new \Exception("Page not found", 404);
}
}

View File

@@ -55,7 +55,7 @@ class Access extends \Core\Model
}
return false;
} catch (PDOException $e) {
echo $e->getMessage();
throw new \Exception($e->getMessage(), 444);
}
}
@@ -97,9 +97,8 @@ class Access extends \Core\Model
}
}
\Core\Session::flash('info', 'Invalid username/password');
return false;
} catch (PDOException $e) {
echo $e->getMessage();
throw new \Exception($e->getMessage(), 444);
}
}

View File

@@ -80,9 +80,8 @@ class Post extends \Core\Model
return $result;
}
}
return false;
} catch (PDOException $e) {
echo $e->getMessage();
throw new \Exception($e->getMessage, 444);
}
}
@@ -102,7 +101,7 @@ class Post extends \Core\Model
}
}
} catch (PDOException $e) {
echo $e->getMessage();
throw new \Exception($e->getMessage(), 444);
}
}
@@ -122,7 +121,7 @@ class Post extends \Core\Model
}
}
} catch (PDOException $e) {
echo $e->getMessage();
throw new \Exception($e->getMessage(), 444);
}
}
}

11
App/Views/Errors/404.html Normal file
View File

@@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block title %}Sorry :-({% endblock %}
{% block body %}
<h2>URL not found - Error 404</h2>
Cannot specify the requested URL. Checking typo ...<br>
<span style="font-size: small;">Sshh! No typos.</span>
{% endblock %}

10
App/Views/Errors/498.html Normal file
View File

@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block title %}Sorry :-({% endblock %}
{% block body %}
<h2>Invalid Token</h2>
Your token is no longer valid. Please try again.<br>
{% endblock %}

10
App/Views/Errors/500.html Normal file
View File

@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block title %}Sorry :-({% endblock %}
{% block body %}
<h2>Aw, crap!</h2>
We couldn't get what you want. Please come back home.
{% endblock %}

View File

@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Error/Exception{% endblock %}
{% block body %}
<h2>{{ title }}</h2>
<p>{{ class }}</p>
<p>{{ message }}</p>
<p>{{ trace_title }}
<pre>{{ trace_content }}</pre>
</p>
<p>{{ file }}</p>
{% endblock %}