From 65bb41ca5e93c07f4a19dd9e2ea8375a818b5b67 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 7 Mar 2017 11:45:20 +0000 Subject: [PATCH] Revert back to 2-value returns --- .../matrix-org/dendrite/clientapi/auth/auth.go | 9 +++++---- .../matrix-org/dendrite/clientapi/readers/sync.go | 7 +------ .../matrix-org/dendrite/clientapi/writers/sendmessage.go | 7 +------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go b/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go index cb809dcd3..e3d8e6fae 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/auth.go @@ -10,9 +10,9 @@ import ( ) // VerifyAccessToken verifies that an access token was supplied in the given HTTP request -// and returns the user ID it corresponds to. Returns err if there was a fatal problem checking -// the token. Returns resErr (an error response which can be sent to the client) if the token is invalid. -func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONResponse, err error) { +// and returns the user ID it corresponds to. Returns resErr (an error response which can be +// sent to the client) if the token is invalid or there was a problem querying the database. +func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONResponse) { token, tokenErr := extractAccessToken(req) if tokenErr != nil { resErr = &util.JSONResponse{ @@ -22,7 +22,8 @@ func VerifyAccessToken(req *http.Request) (userID string, resErr *util.JSONRespo return } if token == "fail" { - err = fmt.Errorf("Fatal error") + res := util.ErrorResponse(fmt.Errorf("Fatal error")) + resErr = &res } // TODO: Check the token against the database return diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go b/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go index 05def8148..c4b3a2474 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/sync.go @@ -4,18 +4,13 @@ import ( "net/http" "github.com/matrix-org/dendrite/clientapi/auth" - "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/util" ) // Sync implements /sync func Sync(req *http.Request) util.JSONResponse { logger := util.GetLogger(req.Context()) - userID, resErr, err := auth.VerifyAccessToken(req) - if err != nil { - logger.WithError(err).Error("Failed to verify access token") - return jsonerror.InternalServerError() - } + userID, resErr := auth.VerifyAccessToken(req) if resErr != nil { return *resErr } diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go b/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go index 4b8ad9052..bbb432ec8 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/sendmessage.go @@ -5,18 +5,13 @@ import ( log "github.com/Sirupsen/logrus" "github.com/matrix-org/dendrite/clientapi/auth" - "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/util" ) // SendMessage implements /rooms/{roomID}/send/{eventType} func SendMessage(req *http.Request, roomID, eventType string) util.JSONResponse { logger := util.GetLogger(req.Context()) - userID, resErr, err := auth.VerifyAccessToken(req) - if err != nil { - logger.WithError(err).Error("Failed to verify access token") - return jsonerror.InternalServerError() - } + userID, resErr := auth.VerifyAccessToken(req) if resErr != nil { return *resErr }