mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
Return 404 when profile is not found
Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>
This commit is contained in:
parent
af08eea46d
commit
7028bfa320
|
|
@ -98,7 +98,13 @@ func (d *Database) GetAccountByPassword(
|
|||
func (d *Database) GetProfileByLocalpart(
|
||||
ctx context.Context, localpart string,
|
||||
) (*authtypes.Profile, error) {
|
||||
return d.profiles.selectProfileByLocalpart(ctx, localpart)
|
||||
profile, err := 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
|
||||
|
|
|
|||
|
|
@ -41,15 +41,12 @@ func GetProfile(
|
|||
JSON: jsonerror.NotFound("Bad method"),
|
||||
}
|
||||
}
|
||||
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
|
||||
|
||||
profile, err := getProfileByUserID(req, accountDB, userID)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
return *err
|
||||
}
|
||||
|
||||
profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
res := common.ProfileResponse{
|
||||
AvatarURL: profile.AvatarURL,
|
||||
DisplayName: profile.DisplayName,
|
||||
|
|
@ -60,19 +57,40 @@ func GetProfile(
|
|||
}
|
||||
}
|
||||
|
||||
// GetAvatarURL implements GET /profile/{userID}/avatar_url
|
||||
func GetAvatarURL(
|
||||
func getProfileByUserID(
|
||||
req *http.Request, accountDB *accounts.Database, userID string,
|
||||
) util.JSONResponse {
|
||||
) (*authtypes.Profile, *util.JSONResponse) {
|
||||
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
resErr := httputil.LogThenError(req, err)
|
||||
return nil, &resErr
|
||||
}
|
||||
|
||||
profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
resErr := httputil.LogThenError(req, err)
|
||||
return nil, &resErr
|
||||
}
|
||||
|
||||
if profile == nil {
|
||||
return nil, &util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
JSON: jsonerror.NotFound("no profile information for this user or this user does not exist"),
|
||||
}
|
||||
}
|
||||
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
// GetAvatarURL implements GET /profile/{userID}/avatar_url
|
||||
func GetAvatarURL(
|
||||
req *http.Request, accountDB *accounts.Database, userID string,
|
||||
) util.JSONResponse {
|
||||
profile, err := getProfileByUserID(req, accountDB, userID)
|
||||
if err != nil {
|
||||
return *err
|
||||
}
|
||||
|
||||
res := common.AvatarURL{
|
||||
AvatarURL: profile.AvatarURL,
|
||||
}
|
||||
|
|
@ -156,15 +174,11 @@ func SetAvatarURL(
|
|||
func GetDisplayName(
|
||||
req *http.Request, accountDB *accounts.Database, userID string,
|
||||
) util.JSONResponse {
|
||||
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
|
||||
profile, err := getProfileByUserID(req, accountDB, userID)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
return *err
|
||||
}
|
||||
|
||||
profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart)
|
||||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
res := common.DisplayName{
|
||||
DisplayName: profile.DisplayName,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue