0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-06-01 12:08:55 +02:00

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"
"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,