From d7a394aeb4c53047f0c3460426e2c24021258ca2 Mon Sep 17 00:00:00 2001 From: Andreas Hennings Date: Thu, 21 Nov 2024 22:59:30 +0100 Subject: [PATCH] Issue #56: Don't disclose exception message to visitor. --- src/Controller/ViewerController.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Controller/ViewerController.php b/src/Controller/ViewerController.php index 24a18157..55bfc80f 100644 --- a/src/Controller/ViewerController.php +++ b/src/Controller/ViewerController.php @@ -17,6 +17,7 @@ use Drupal\collabora_online\Exception\CollaboraNotAvailableException; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Render\RendererInterface; +use Drupal\Core\Utility\Error; use Drupal\media\Entity\Media; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -62,15 +63,12 @@ public function editor(Media $media, Request $request, $edit = FALSE) { $wopi_client_url = $this->discovery->getWopiClientURL(); } catch (CollaboraNotAvailableException $e) { - $error_msg = $this->t('The Collabora Online server is not available: @message', [ - '@message' => $e->getCode() . ': ' . $e->getMessage(), - ]); - $error_msg = (string) $this->t('Viewer error: @message', [ - '@message' => $error_msg, - ]); - $this->getLogger('cool')->error($error_msg); + $this->getLogger('cool')->warning( + "Collabora Online is not available.
\n" . Error::DEFAULT_ERROR_MESSAGE, + Error::decodeException($e) + [], + ); return new Response( - $error_msg, + (string) $this->t('The Collabora Online editor/viewer is not available.'), Response::HTTP_BAD_REQUEST, ['content-type' => 'text/plain'], );