Use the new Symfony error handler

This commit is contained in:
Pierre Rudloff 2020-05-13 22:57:25 +02:00
parent b670b16ca2
commit 6a19a1ddc1
4 changed files with 44 additions and 44 deletions

View file

@ -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": {

70
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0963a360e0cc19e97da7da9b8cad2285",
"content-hash": "9860b748974de6e19945cfae8619d223",
"packages": [
{
"name": "aura/session",
@ -932,16 +932,16 @@
},
{
"name": "psr/log",
"version": "1.1.0",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
"shasum": ""
},
"require": {
@ -950,7 +950,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
},
"autoload": {
@ -975,7 +975,7 @@
"psr",
"psr-3"
],
"time": "2018-11-20T15:27:04+00:00"
"time": "2020-03-23T09:12:05+00:00"
},
{
"name": "ralouphie/getallheaders",
@ -5841,38 +5841,37 @@
"time": "2019-10-28T04:36:32+00:00"
},
{
"name": "symfony/debug",
"version": "v4.4.0",
"name": "symfony/error-handler",
"version": "v5.0.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/debug.git",
"reference": "b24b791f817116b29e52a63e8544884cf9a40757"
"url": "https://github.com/symfony/error-handler.git",
"reference": "949ffc17c3ac3a9f8e6232220e2da33913c04ea4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/b24b791f817116b29e52a63e8544884cf9a40757",
"reference": "b24b791f817116b29e52a63e8544884cf9a40757",
"url": "https://api.github.com/repos/symfony/error-handler/zipball/949ffc17c3ac3a9f8e6232220e2da33913c04ea4",
"reference": "949ffc17c3ac3a9f8e6232220e2da33913c04ea4",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"psr/log": "~1.0"
},
"conflict": {
"symfony/http-kernel": "<3.4"
"php": "^7.2.5",
"psr/log": "^1.0",
"symfony/var-dumper": "^4.4|^5.0"
},
"require-dev": {
"symfony/http-kernel": "^3.4|^4.0|^5.0"
"symfony/http-kernel": "^4.4|^5.0",
"symfony/serializer": "^4.4|^5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.4-dev"
"dev-master": "5.0-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Debug\\": ""
"Symfony\\Component\\ErrorHandler\\": ""
},
"exclude-from-classmap": [
"/Tests/"
@ -5892,38 +5891,37 @@
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Debug Component",
"description": "Symfony ErrorHandler Component",
"homepage": "https://symfony.com",
"time": "2019-11-10T17:54:30+00:00"
"time": "2020-03-30T14:14:32+00:00"
},
{
"name": "symfony/var-dumper",
"version": "v4.4.0",
"version": "v5.0.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-dumper.git",
"reference": "eade2890f8b0eeb279b6cf41b50a10007294490f"
"reference": "09de28632f16f81058a85fcf318397218272a07b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/eade2890f8b0eeb279b6cf41b50a10007294490f",
"reference": "eade2890f8b0eeb279b6cf41b50a10007294490f",
"url": "https://api.github.com/repos/symfony/var-dumper/zipball/09de28632f16f81058a85fcf318397218272a07b",
"reference": "09de28632f16f81058a85fcf318397218272a07b",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php72": "~1.5"
"php": "^7.2.5",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/console": "<3.4"
"phpunit/phpunit": "<5.4.3",
"symfony/console": "<4.4"
},
"require-dev": {
"ext-iconv": "*",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/console": "^4.4|^5.0",
"symfony/process": "^4.4|^5.0",
"twig/twig": "^1.34|^2.4|^3.0"
"twig/twig": "^2.4|^3.0"
},
"suggest": {
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
@ -5936,7 +5934,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.4-dev"
"dev-master": "5.0-dev"
}
},
"autoload": {
@ -5970,7 +5968,7 @@
"debug",
"dump"
],
"time": "2019-11-12T14:51:11+00:00"
"time": "2020-04-12T16:45:47+00:00"
},
{
"name": "theseer/tokenizer",

View file

@ -9,14 +9,15 @@ namespace Alltube\Controller;
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.
@ -240,9 +241,9 @@ class FrontController extends BaseController
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 {

View file

@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Alltube\Config;
use Alltube\Controller\DownloadController;
use Alltube\Controller\FrontController;
@ -11,7 +12,7 @@ use Alltube\UglyRouter;
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']));