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.
This commit is contained in:
Jan Böhmer 2024-08-24 15:49:45 +02:00
parent 8193e7a68e
commit b99777cde1

View file

@ -52,11 +52,11 @@ class AttachmentFileController extends AbstractController
} }
if ($attachment->isExternal()) { 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)) { 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); $file_path = $helper->toAbsoluteFilePath($attachment);
@ -81,11 +81,11 @@ class AttachmentFileController extends AbstractController
} }
if ($attachment->isExternal()) { 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)) { 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); $file_path = $helper->toAbsoluteFilePath($attachment);