Cleaner error handling

This commit is contained in:
Pierre Rudloff 2016-05-01 01:25:08 +02:00
parent 43804eebad
commit aba0243fd2
2 changed files with 116 additions and 118 deletions

View file

@ -114,7 +114,6 @@ class FrontController
$this->config = Config::getInstance(); $this->config = Config::getInstance();
if (isset($params["url"])) { if (isset($params["url"])) {
if (isset($params['audio'])) { if (isset($params['audio'])) {
try {
try { try {
$url = $this->download->getURL($params["url"], 'bestaudio[protocol^=http]'); $url = $this->download->getURL($params["url"], 'bestaudio[protocol^=http]');
return $response->withRedirect($url); return $response->withRedirect($url);
@ -201,11 +200,7 @@ class FrontController
} }
return $response; return $response;
} }
} catch (\Exception $e) {
$error = $e->getMessage();
}
} else { } else {
try {
$video = $this->download->getJSON($params["url"]); $video = $this->download->getJSON($params["url"]);
$container->view->render( $container->view->render(
$response, $response,
@ -222,12 +217,13 @@ class FrontController
) )
); );
$container->view->render($response, 'footer.tpl'); $container->view->render($response, 'footer.tpl');
} catch (\Exception $e) {
$error = $e->getMessage();
} }
} }
} }
if (isset($error)) {
public function error($request, $response, $exception)
{
global $container;
$container->view->render( $container->view->render(
$response, $response,
'head.tpl', 'head.tpl',
@ -239,11 +235,11 @@ class FrontController
$response, $response,
'error.tpl', 'error.tpl',
array( array(
'errors'=>$error 'errors'=>$exception->getMessage()
) )
); );
$container->view->render($response, 'footer.tpl'); $container->view->render($response, 'footer.tpl');
} return $response;
} }
/** /**

View file

@ -30,6 +30,8 @@ $container['view'] = function ($c) {
$controller = new FrontController(); $controller = new FrontController();
$container['errorHandler'] = array($controller, 'error');
$app->get( $app->get(
'/', '/',
array($controller, 'index') array($controller, 'index')