Revert back to 2-value returns

This commit is contained in:
Kegan Dougal 2017-03-07 11:45:20 +00:00
parent 4137b6185d
commit 65bb41ca5e
3 changed files with 7 additions and 16 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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
}