diff options
author | Nils Adermann <naderman@naderman.de> | 2015-01-22 16:16:21 +0100 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2015-01-22 16:16:21 +0100 |
commit | 40ab75478ed7427985e4d147eb6573ce8bb351fc (patch) | |
tree | 8cd31410ef67f9ad1978e48272640c5f67bc2de9 /phpBB/phpbb/event | |
parent | a737eeb6cea2d494be4c8ae5e1101d1015746191 (diff) | |
parent | 7fef91afd28290ce268f671eb525dedf5ade944d (diff) | |
download | forums-40ab75478ed7427985e4d147eb6573ce8bb351fc.tar forums-40ab75478ed7427985e4d147eb6573ce8bb351fc.tar.gz forums-40ab75478ed7427985e4d147eb6573ce8bb351fc.tar.bz2 forums-40ab75478ed7427985e4d147eb6573ce8bb351fc.tar.xz forums-40ab75478ed7427985e4d147eb6573ce8bb351fc.zip |
Merge pull request #3173 from Nicofuma/ticket/13361
[ticket/13361] Improve the exception listener
Diffstat (limited to 'phpBB/phpbb/event')
-rw-r--r-- | phpBB/phpbb/event/kernel_exception_subscriber.php | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index 44e87507f9..eb7831ad34 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -14,9 +14,10 @@ namespace phpbb\event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpFoundation\JsonResponse; +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 @@ -53,23 +54,55 @@ class kernel_exception_subscriber implements EventSubscriberInterface */ public function on_kernel_exception(GetResponseForExceptionEvent $event) { - page_header($this->user->lang('INFORMATION')); - $exception = $event->getException(); - $this->template->assign_vars(array( - 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - 'MESSAGE_TEXT' => $exception->getMessage(), - )); + $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())); + } + + if (!$event->getRequest()->isXmlHttpRequest()) + { + page_header($this->user->lang('INFORMATION')); + + $this->template->assign_vars(array( + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + 'MESSAGE_TEXT' => $message, + )); + + $this->template->set_filenames(array( + 'body' => 'message_body.html', + )); + + page_footer(true, false, false); + + $response = new Response($this->template->assign_display('body'), 500); + } + else + { + $data = array(); + + if (!empty($message)) + { + $data['message'] = $message; + } + + if (defined('DEBUG')) + { + $data['trace'] = $exception->getTrace(); + } - $this->template->set_filenames(array( - 'body' => 'message_body.html', - )); + $response = new JsonResponse($data, 500); + } - page_footer(true, false, false); + if ($exception instanceof HttpExceptionInterface) + { + $response->setStatusCode($exception->getStatusCode()); + $response->headers->add($exception->getHeaders()); + } - $status_code = $exception instanceof HttpException ? $exception->getStatusCode() : 500; - $response = new Response($this->template->assign_display('body'), $status_code); $event->setResponse($response); } |