Skip to content

Commit

Permalink
Use the new Symfony error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed May 13, 2020
1 parent b670b16 commit 6a19a1d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"roave/security-advisories": "dev-master",
"smarty-gettext/smarty-gettext": "^1.6",
"squizlabs/php_codesniffer": "^3.5",
"symfony/debug": "^4.0",
"symfony/var-dumper": "^4.0",
"symfony/error-handler": "^5.0",
"symfony/var-dumper": "^5.0",
"ytdl-org/youtube-dl": "^2020.03.24"
},
"extra": {
Expand Down
70 changes: 34 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions controllers/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use Alltube\Exception\PasswordException;
use Alltube\Locale;
use Alltube\Video;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Throwable;
use Exception;
use Psr\Container\ContainerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Smarty;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\Debug\Exception\FlattenException;

/**
* Main controller.
Expand Down Expand Up @@ -240,9 +241,9 @@ public function info(Request $request, Response $response)
public function error(Request $request, Response $response, Throwable $error)
{
if ($this->config->debug) {
$exception = FlattenException::createFromThrowable($error);
$handler = new ExceptionHandler();
$response->getBody()->write($handler->getHtml($exception));
$renderer = new HtmlErrorRenderer(true);
$exception = $renderer->render($error);
$response->getBody()->write($exception->getAsString());

return $response->withStatus($exception->getStatusCode());
} else {
Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Alltube\Config;
use Alltube\Controller\DownloadController;
use Alltube\Controller\FrontController;
Expand All @@ -11,7 +12,7 @@
use Alltube\ViewFactory;
use Slim\App;
use Slim\Container;
use Symfony\Component\Debug\Debug;
use Symfony\Component\ErrorHandler\Debug;

if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
Expand Down

0 comments on commit 6a19a1d

Please sign in to comment.