From 74e8f9bd4e6c55dddb473e1a301d2cae9edb6e50 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 Jan 2015 17:14:14 +0100 Subject: [ticket/13361] Support ajax request (send a json response) PHPBB3-13361 --- phpBB/phpbb/event/kernel_exception_subscriber.php | 34 +++++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index 1e536c1b8f..b6b34675f0 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -14,6 +14,7 @@ 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; @@ -64,18 +65,33 @@ class kernel_exception_subscriber implements EventSubscriberInterface $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' => $message, - )); + if (!$event->getRequest()->isXmlHttpRequest()) + { + $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); - $this->template->set_filenames(array( - 'body' => 'message_body.html', - )); + $response = new Response($this->template->assign_display('body'), 500); + } + else + { + $data = array(); + $data['message'] = $message; - page_footer(true, false, false); + if (defined('DEBUG')) + { + $data['trace'] = $exception->getTrace(); + } - $response = new Response($this->template->assign_display('body'), 500); + $response = new JsonResponse($message, 500); + } if ($exception instanceof HttpExceptionInterface) { -- cgit v1.2.1