mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-25 05:01:41 +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"
|
"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,
|
||||||
|
Loading…
Reference in New Issue
Block a user