From c366affa2674524ca5ed296d2428f20ebdbed437 Mon Sep 17 00:00:00 2001 From: Jihan Kim Date: Thu, 14 Aug 2014 11:11:39 +0900 Subject: [PATCH] Attachment: treat error if file doesn't exists on storage Response as 500 Internal Server Error and log it as error. --- app/controllers/AttachmentApp.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/AttachmentApp.java b/app/controllers/AttachmentApp.java index 4b7adad56..ea397b31a 100644 --- a/app/controllers/AttachmentApp.java +++ b/app/controllers/AttachmentApp.java @@ -139,6 +139,11 @@ public static Result getFile(Long id) throws IOException { File file = attachment.getFile(); + if(file != null && !file.exists()){ + Logger.error("Attachment ID:" + id + " (" + file.getAbsolutePath() + ") does not exist on storage"); + return internalServerError("The file does not exist"); + } + String filename = HttpUtil.encodeContentDisposition(attachment.name); response().setHeader("Content-Type", attachment.mimeType);