-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding logging and error handlaing for production environment
- Loading branch information
Filipe Silva
committed
Feb 2, 2015
1 parent
4282e72
commit 17a1d08
Showing
5 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>{{ translate('File not found') }}</title> | ||
</head> | ||
<body> | ||
<h1>{{ translate('File not found') }}</h1> | ||
<p>{{ translate('The file you specify is not found in this server.') }}</a></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
<title>{{ translate ('Sorry...') }}</title> | ||
</head> | ||
<body> | ||
<h1>{{ translate ('Sorry...') }}</h1> | ||
<h3>{{ translate ("It\'s not you. It\'s us.") }}</h3> | ||
<p>{{ translate ("We\'re experiencing an internal server problem. <br/> | ||
Please try again later or contact <a href=\"#\">a system adminitrator.</a>")|raw }}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* Production error handler | ||
* | ||
* @package Slick\Mvc\Whoops\Handler | ||
* @author Filipe Silva <silvam.filipe@gmail.com> | ||
* @copyright 2014 Filipe Silva | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
* @since Version 1.1.0 | ||
*/ | ||
|
||
namespace Slick\Mvc\Whoops\Handler; | ||
|
||
use Slick\Log\Log; | ||
use Slick\Mvc\Application; | ||
use Slick\Template\Template; | ||
use Whoops\Handler\PlainTextHandler; | ||
use Slick\Mvc\Exception\ActionNotFoundException; | ||
use Slick\Mvc\Exception\ControllerNotFoundException; | ||
|
||
/** | ||
* Production error handler | ||
* | ||
* @package Slick\Mvc\Whoops\Handler | ||
* @author Filipe Silva <silvam.filipe@gmail.com> | ||
*/ | ||
class Production extends PlainTextHandler | ||
{ | ||
|
||
/** | ||
* @var Application | ||
*/ | ||
private $app; | ||
|
||
/** | ||
* Sets application | ||
* | ||
* @param Application $app | ||
* @return self | ||
*/ | ||
public function setApplication(Application $app) | ||
{ | ||
$this->app = $app; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Handle the exception | ||
*/ | ||
public function handle() | ||
{ | ||
$exception = $this->getException(); | ||
|
||
Log::logger('ErrorHandler')->error($exception->getMessage(), [ | ||
'exception' => get_class($exception), | ||
'file' => sprintf( | ||
"%s on line %d", | ||
$exception->getFile(), | ||
$exception->getLine() | ||
) | ||
]); | ||
|
||
$template = new Template(); | ||
|
||
$template = $template->initialize(); | ||
$view = 'errors/500.html.twig'; | ||
$code = 500; | ||
if ( | ||
($exception instanceof ControllerNotFoundException) || | ||
($exception instanceof ActionNotFoundException) | ||
) { | ||
$view = 'errors/404.html.twig'; | ||
$code = 404; | ||
} | ||
|
||
$data = ['exception' => $exception]; | ||
$html = $template->parse($view) | ||
->process($data); | ||
|
||
$this->app->response->setStatusCode($code) | ||
->setContent($html); | ||
|
||
$this->app->response->send(); | ||
} | ||
|
||
} |