From b99777cde1ed305b8e3d6f30fd4b4045afa8bb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 24 Aug 2024 15:49:45 +0200 Subject: [PATCH] Return a 404 message, instead of creating an 500 Runtime exception, when a file associated with an attachment is not existing. This fails more gracefully, and do not pollute log files. --- src/Controller/AttachmentFileController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controller/AttachmentFileController.php b/src/Controller/AttachmentFileController.php index 5ea62aeb..936d27c5 100644 --- a/src/Controller/AttachmentFileController.php +++ b/src/Controller/AttachmentFileController.php @@ -52,11 +52,11 @@ class AttachmentFileController extends AbstractController } if ($attachment->isExternal()) { - throw new RuntimeException('You can not download external attachments!'); + throw $this->createNotFoundException('The file for this attachment is external and can not stored locally!'); } if (!$helper->isFileExisting($attachment)) { - throw new RuntimeException('The file associated with the attachment is not existing!'); + throw $this->createNotFoundException('The file associated with the attachment is not existing!'); } $file_path = $helper->toAbsoluteFilePath($attachment); @@ -81,11 +81,11 @@ class AttachmentFileController extends AbstractController } if ($attachment->isExternal()) { - throw new RuntimeException('You can not download external attachments!'); + throw $this->createNotFoundException('The file for this attachment is external and can not stored locally!'); } if (!$helper->isFileExisting($attachment)) { - throw new RuntimeException('The file associated with the attachment is not existing!'); + throw $this->createNotFoundException('The file associated with the attachment is not existing!'); } $file_path = $helper->toAbsoluteFilePath($attachment);