1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/13361] Improve the exception listener

PHPBB3-13361
This commit is contained in:
Tristan Darricau
2014-11-22 23:10:19 +01:00
parent 8b71103836
commit b00d02496e
5 changed files with 168 additions and 4 deletions

View File

@@ -14,9 +14,9 @@
namespace phpbb\event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
class kernel_exception_subscriber implements EventSubscriberInterface
@@ -57,9 +57,16 @@ class kernel_exception_subscriber implements EventSubscriberInterface
$exception = $event->getException();
$message = $exception->getMessage();
if ($exception instanceof \phpbb\exception\exception_interface)
{
$message = call_user_func_array(array($this->user, 'lang'), array_merge(array($message), $exception->get_parameters()));
}
$this->template->assign_vars(array(
'MESSAGE_TITLE' => $this->user->lang('INFORMATION'),
'MESSAGE_TEXT' => $exception->getMessage(),
'MESSAGE_TEXT' => $message,
));
$this->template->set_filenames(array(
@@ -68,8 +75,14 @@ class kernel_exception_subscriber implements EventSubscriberInterface
page_footer(true, false, false);
$status_code = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
$response = new Response($this->template->assign_display('body'), $status_code);
$response = new Response($this->template->assign_display('body'), 500);
if ($exception instanceof HttpExceptionInterface)
{
$response->setStatusCode($exception->getStatusCode());
$response->headers->add($exception->getHeaders());
}
$event->setResponse($response);
}