From a29048abd6ea13ec00449c4c1c751c035cf5ed1c Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 9 Sep 2017 17:08:27 +0200 Subject: [ticket/14933] Make "route not found" more user-friendly PHPBB3-14933 --- phpBB/phpbb/event/kernel_exception_subscriber.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index b7a54f2608..f7582c5d90 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -16,12 +16,20 @@ namespace phpbb\event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpFoundation\Response; class kernel_exception_subscriber implements EventSubscriberInterface { + /** + * Set to true to show full exception messages + * + * @var bool + */ + protected $debug; + /** * Template object * @@ -45,8 +53,9 @@ class kernel_exception_subscriber implements EventSubscriberInterface * @param \phpbb\template\template $template Template object * @param \phpbb\language\language $language Language object */ - public function __construct(\phpbb\template\template $template, \phpbb\language\language $language) + public function __construct(\phpbb\template\template $template, \phpbb\language\language $language, $debug = false) { + $this->debug = $debug || defined('DEBUG'); $this->template = $template; $this->language = $language; $this->type_caster = new \phpbb\request\type_cast_helper(); @@ -69,6 +78,10 @@ class kernel_exception_subscriber implements EventSubscriberInterface { $message = $this->language->lang_array($message, $exception->get_parameters()); } + else if (!$this->debug && $exception instanceof NotFoundHttpException) + { + $message = $this->language->lang('PAGE_NOT_FOUND'); + } // Show text in bold $message = preg_replace('#<(/?strong)>#i', '<$1>', $message); @@ -99,7 +112,7 @@ class kernel_exception_subscriber implements EventSubscriberInterface $data['message'] = $message; } - if (defined('DEBUG')) + if ($this->debug) { $data['trace'] = $exception->getTrace(); } -- cgit v1.2.1