mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-13 09:53:10 -06:00
Handler sql.ErrNoRows and avoid returning nil
update federation GetProfile as well Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>
This commit is contained in:
parent
7028bfa320
commit
82f4e54931
|
|
@ -98,13 +98,7 @@ func (d *Database) GetAccountByPassword(
|
||||||
func (d *Database) GetProfileByLocalpart(
|
func (d *Database) GetProfileByLocalpart(
|
||||||
ctx context.Context, localpart string,
|
ctx context.Context, localpart string,
|
||||||
) (*authtypes.Profile, error) {
|
) (*authtypes.Profile, error) {
|
||||||
profile, err := d.profiles.selectProfileByLocalpart(ctx, localpart)
|
return d.profiles.selectProfileByLocalpart(ctx, localpart)
|
||||||
// err == sql.ErrNoRows signifies that this profile is not in the db
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return profile, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAvatarURL updates the avatar URL of the profile associated with the given
|
// SetAvatarURL updates the avatar URL of the profile associated with the given
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
|
|
@ -57,6 +58,7 @@ func GetProfile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getProfileByUserID returns the profile for userID, otherwise returns an error response
|
||||||
func getProfileByUserID(
|
func getProfileByUserID(
|
||||||
req *http.Request, accountDB *accounts.Database, userID string,
|
req *http.Request, accountDB *accounts.Database, userID string,
|
||||||
) (*authtypes.Profile, *util.JSONResponse) {
|
) (*authtypes.Profile, *util.JSONResponse) {
|
||||||
|
|
@ -67,16 +69,14 @@ func getProfileByUserID(
|
||||||
}
|
}
|
||||||
|
|
||||||
profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart)
|
profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart)
|
||||||
if err != nil {
|
if err == sql.ErrNoRows {
|
||||||
resErr := httputil.LogThenError(req, err)
|
|
||||||
return nil, &resErr
|
|
||||||
}
|
|
||||||
|
|
||||||
if profile == nil {
|
|
||||||
return nil, &util.JSONResponse{
|
return nil, &util.JSONResponse{
|
||||||
Code: http.StatusNotFound,
|
Code: http.StatusNotFound,
|
||||||
JSON: jsonerror.NotFound("no profile information for this user or this user does not exist"),
|
JSON: jsonerror.NotFound("no profile information for this user or this user does not exist"),
|
||||||
}
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
resErr := httputil.LogThenError(req, err)
|
||||||
|
return nil, &resErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return profile, nil
|
return profile, nil
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
|
|
@ -52,7 +53,12 @@ func GetProfile(
|
||||||
}
|
}
|
||||||
|
|
||||||
profile, err := accountDB.GetProfileByLocalpart(httpReq.Context(), localpart)
|
profile, err := accountDB.GetProfileByLocalpart(httpReq.Context(), localpart)
|
||||||
if err != nil {
|
if err == sql.ErrNoRows {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusNotFound,
|
||||||
|
JSON: jsonerror.NotFound("no profile information for this user or this user does not exist"),
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
return httputil.LogThenError(httpReq, err)
|
return httputil.LogThenError(httpReq, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue