diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2023-07-28 08:40:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-28 08:40:05 +0200 |
commit | 3f727485d6e21a603e4df1cb31c3795cc1023caa (patch) | |
tree | f61cdcd6ce928ccc2ad025b4a629d537af807d39 | |
parent | 79d4a0e399bb68920b81bc877744108095c06f1a (diff) |
Send a more generic error message to clients if the file can't be found (#3161)
Fixes #3160
-rw-r--r-- | mediaapi/routing/download.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go index 8fb1b653..51afa1f9 100644 --- a/mediaapi/routing/download.go +++ b/mediaapi/routing/download.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" "io" + "io/fs" "mime" "net/http" "net/url" @@ -126,6 +127,17 @@ func Download( activeRemoteRequests, activeThumbnailGeneration, ) if err != nil { + // If we bubbled up a os.PathError, e.g. no such file or directory, don't send + // it to the client, be more generic. + var perr *fs.PathError + if errors.As(err, &perr) { + dReq.Logger.WithError(err).Error("failed to open file") + dReq.jsonErrorResponse(w, util.JSONResponse{ + Code: http.StatusNotFound, + JSON: spec.NotFound("File not found"), + }) + return + } // TODO: Handle the fact we might have started writing the response dReq.jsonErrorResponse(w, util.JSONResponse{ Code: http.StatusNotFound, |