From f88c537f4368d6d868f459959dc2b77f73fc74fd Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Mon, 22 May 2017 21:03:57 +0200 Subject: [PATCH] mediaapi/writers/download: Separate 404 and 500 due to db query failure --- .../dendrite/mediaapi/writers/download.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go index bdb63d4a7..bc6fb6d98 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go @@ -163,13 +163,23 @@ func Download(w http.ResponseWriter, req *http.Request, origin gomatrixserverlib activeRemoteRequests.Unlock() r.respondFromRemoteFile(w, cfg.AbsBasePath, cfg.MaxFileSizeBytes, db, activeRemoteRequests) - } else { - // 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 + } else if err == sql.ErrNoRows && r.MediaMetadata.Origin == cfg.ServerName { + // 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.jsonErrorResponse(w, util.JSONResponse{ Code: 404, 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"), + }) } }