mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-10 08:23:11 -06:00
mediaapi/writers/download: Separate 404 and 500 due to db query failure
This commit is contained in:
parent
3d8aec28b1
commit
f88c537f43
|
|
@ -163,13 +163,23 @@ func Download(w http.ResponseWriter, req *http.Request, origin gomatrixserverlib
|
||||||
activeRemoteRequests.Unlock()
|
activeRemoteRequests.Unlock()
|
||||||
|
|
||||||
r.respondFromRemoteFile(w, cfg.AbsBasePath, cfg.MaxFileSizeBytes, db, activeRemoteRequests)
|
r.respondFromRemoteFile(w, cfg.AbsBasePath, cfg.MaxFileSizeBytes, db, activeRemoteRequests)
|
||||||
} else {
|
} else if err == sql.ErrNoRows && r.MediaMetadata.Origin == cfg.ServerName {
|
||||||
// If we do not have a record and the origin is local, or if we have another error from the database, the file is not found
|
// If we do not have a record and the origin is local, the file is not found
|
||||||
r.Logger.WithError(err).Warn("Failed to look up file in database")
|
r.Logger.WithError(err).Warn("Failed to look up file in database")
|
||||||
r.jsonErrorResponse(w, util.JSONResponse{
|
r.jsonErrorResponse(w, util.JSONResponse{
|
||||||
Code: 404,
|
Code: 404,
|
||||||
JSON: jsonerror.NotFound(fmt.Sprintf("File with media ID %q does not exist", r.MediaMetadata.MediaID)),
|
JSON: jsonerror.NotFound(fmt.Sprintf("File with media ID %q does not exist", r.MediaMetadata.MediaID)),
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// Another error from the database
|
||||||
|
r.Logger.WithError(err).WithFields(log.Fields{
|
||||||
|
"MediaID": r.MediaMetadata.MediaID,
|
||||||
|
"Origin": r.MediaMetadata.Origin,
|
||||||
|
}).Error("Error querying the database.")
|
||||||
|
r.jsonErrorResponse(w, util.JSONResponse{
|
||||||
|
Code: 500,
|
||||||
|
JSON: jsonerror.Unknown("Internal server error"),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue