Send a more generic error message to clients if the file can't be found (#3161)

Fixes #3160
This commit is contained in:
Till 2023-07-28 08:40:05 +02:00 committed by GitHub
parent 79d4a0e399
commit 3f727485d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/fs"
"mime" "mime"
"net/http" "net/http"
"net/url" "net/url"
@ -126,6 +127,17 @@ func Download(
activeRemoteRequests, activeThumbnailGeneration, activeRemoteRequests, activeThumbnailGeneration,
) )
if err != nil { 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 // TODO: Handle the fact we might have started writing the response
dReq.jsonErrorResponse(w, util.JSONResponse{ dReq.jsonErrorResponse(w, util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,