Cleaner error handling
This commit is contained in:
parent
43804eebad
commit
aba0243fd2
2 changed files with 116 additions and 118 deletions
|
@ -114,7 +114,6 @@ class FrontController
|
|||
$this->config = Config::getInstance();
|
||||
if (isset($params["url"])) {
|
||||
if (isset($params['audio'])) {
|
||||
try {
|
||||
try {
|
||||
$url = $this->download->getURL($params["url"], 'bestaudio[protocol^=http]');
|
||||
return $response->withRedirect($url);
|
||||
|
@ -201,11 +200,7 @@ class FrontController
|
|||
}
|
||||
return $response;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$video = $this->download->getJSON($params["url"]);
|
||||
$container->view->render(
|
||||
$response,
|
||||
|
@ -222,12 +217,13 @@ class FrontController
|
|||
)
|
||||
);
|
||||
$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(
|
||||
$response,
|
||||
'head.tpl',
|
||||
|
@ -239,11 +235,11 @@ class FrontController
|
|||
$response,
|
||||
'error.tpl',
|
||||
array(
|
||||
'errors'=>$error
|
||||
'errors'=>$exception->getMessage()
|
||||
)
|
||||
);
|
||||
$container->view->render($response, 'footer.tpl');
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,8 @@ $container['view'] = function ($c) {
|
|||
|
||||
$controller = new FrontController();
|
||||
|
||||
$container['errorHandler'] = array($controller, 'error');
|
||||
|
||||
$app->get(
|
||||
'/',
|
||||
array($controller, 'index')
|
||||
|
|
Loading…
Reference in a new issue