From b00d02496e9ec8281a6e0d6637772c55a7011c60 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 22 Nov 2014 23:10:19 +0100 Subject: [ticket/13361] Improve the exception listener PHPBB3-13361 --- phpBB/phpbb/event/kernel_exception_subscriber.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/event/kernel_exception_subscriber.php') diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index 44e87507f9..1e536c1b8f 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -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); } -- cgit v1.2.1 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/event/kernel_exception_subscriber.php') 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 From 1f4bb2c1495e8d2641abe9606f14281e810feee4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 Jan 2015 18:15:19 +0100 Subject: [ticket/13361] Add tests PHPBB3-13361 --- phpBB/phpbb/event/kernel_exception_subscriber.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/event/kernel_exception_subscriber.php') diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index b6b34675f0..01940a4fa9 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -54,8 +54,6 @@ class kernel_exception_subscriber implements EventSubscriberInterface */ public function on_kernel_exception(GetResponseForExceptionEvent $event) { - page_header($this->user->lang('INFORMATION')); - $exception = $event->getException(); $message = $exception->getMessage(); @@ -67,6 +65,8 @@ class kernel_exception_subscriber implements EventSubscriberInterface if (!$event->getRequest()->isXmlHttpRequest()) { + page_header($this->user->lang('INFORMATION')); + $this->template->assign_vars(array( 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 'MESSAGE_TEXT' => $message, @@ -83,7 +83,11 @@ class kernel_exception_subscriber implements EventSubscriberInterface else { $data = array(); - $data['message'] = $message; + + if (!empty($message)) + { + $data['message'] = $message; + } if (defined('DEBUG')) { -- cgit v1.2.1 From 8ef238ea73b481a717d8b68fb1fd7d1b8799d7f2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 14 Jan 2015 11:13:28 +0100 Subject: [ticket/13361] Fix the JsonResponse in the exception listener PHPBB3-13361 --- phpBB/phpbb/event/kernel_exception_subscriber.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/event/kernel_exception_subscriber.php') diff --git a/phpBB/phpbb/event/kernel_exception_subscriber.php b/phpBB/phpbb/event/kernel_exception_subscriber.php index 01940a4fa9..eb7831ad34 100644 --- a/phpBB/phpbb/event/kernel_exception_subscriber.php +++ b/phpBB/phpbb/event/kernel_exception_subscriber.php @@ -94,7 +94,7 @@ class kernel_exception_subscriber implements EventSubscriberInterface $data['trace'] = $exception->getTrace(); } - $response = new JsonResponse($message, 500); + $response = new JsonResponse($data, 500); } if ($exception instanceof HttpExceptionInterface) -- cgit v1.2.1