From f46b61399bade712f0f77eef5d7762450613c4f3 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Sun, 27 Jan 2019 00:32:37 +0000 Subject: [PATCH] Fix broken page when file is missing (#160) With the localfs backend, it's possible for a file to be removed but its metadata file to remain intact. In this case, viewing the selif URL for that file would return a broken page with two error pages stacked on top of each other. This changes fixes that by replacing the output in that case with a single "Unable to open file." error message. --- fileserve.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fileserve.go b/fileserve.go index a3a249e..8948d45 100644 --- a/fileserve.go +++ b/fileserve.go @@ -38,8 +38,12 @@ func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) { w.Header().Set("Referrer-Policy", Config.fileReferrerPolicy) _, reader, err := storageBackend.Get(fileName) - if err != nil { - oopsHandler(c, w, r, RespAUTO, err.Error()) + if err == backends.NotFoundErr { + notFoundHandler(c, w, r) + return + } else if err != nil { + oopsHandler(c, w, r, RespAUTO, "Unable to open file.") + return } w.Header().Set("Content-Type", metadata.Mimetype)