Skip to content

Commit b99777c

Browse files
committed
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.
1 parent 8193e7a commit b99777c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Controller/AttachmentFileController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public function download(Attachment $attachment, AttachmentManager $helper): Bin
5252
}
5353

5454
if ($attachment->isExternal()) {
55-
throw new RuntimeException('You can not download external attachments!');
55+
throw $this->createNotFoundException('The file for this attachment is external and can not stored locally!');
5656
}
5757

5858
if (!$helper->isFileExisting($attachment)) {
59-
throw new RuntimeException('The file associated with the attachment is not existing!');
59+
throw $this->createNotFoundException('The file associated with the attachment is not existing!');
6060
}
6161

6262
$file_path = $helper->toAbsoluteFilePath($attachment);
@@ -81,11 +81,11 @@ public function view(Attachment $attachment, AttachmentManager $helper): BinaryF
8181
}
8282

8383
if ($attachment->isExternal()) {
84-
throw new RuntimeException('You can not download external attachments!');
84+
throw $this->createNotFoundException('The file for this attachment is external and can not stored locally!');
8585
}
8686

8787
if (!$helper->isFileExisting($attachment)) {
88-
throw new RuntimeException('The file associated with the attachment is not existing!');
88+
throw $this->createNotFoundException('The file associated with the attachment is not existing!');
8989
}
9090

9191
$file_path = $helper->toAbsoluteFilePath($attachment);

0 commit comments

Comments
 (0)