From 50872269b3c52b0731839d683f807442e4e56c28 Mon Sep 17 00:00:00 2001 From: Doug Lauder Date: Mon, 3 Apr 2023 17:43:58 -0400 Subject: [PATCH] Avoid panic in file request handler on error (#4693) Co-authored-by: Mattermost Build --- server/api/files.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/api/files.go b/server/api/files.go index c2a6eaa71..2868e5507 100644 --- a/server/api/files.go +++ b/server/api/files.go @@ -19,6 +19,7 @@ import ( "github.com/mattermost/focalboard/server/model" "github.com/mattermost/focalboard/server/services/audit" + mmModel "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/mlog" @@ -167,7 +168,14 @@ func (a *API) handleServeFile(w http.ResponseWriter, r *http.Request) { _ = a.app.MoveFile(board.ChannelID, board.TeamID, boardID, filename) } + if err != nil { + // if err is still not nil then it is an error other than `not found` so we must + // return the error to the requestor. fileReader and Fileinfo are nil in this case. + a.errorResponse(w, r, err) + } + defer fileReader.Close() + mimeType := "" var fileSize int64 if fileInfo != nil {