mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-21 11:11:39 +00:00
Send a more generic error message to clients if the file can't be found (#3161)
Fixes #3160
This commit is contained in:
parent
79d4a0e399
commit
3f727485d6
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user