mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -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(
|
||||
ctx context.Context, localpart string,
|
||||
) (*authtypes.Profile, error) {
|
||||
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
|
||||
return d.profiles.selectProfileByLocalpart(ctx, localpart)
|
||||
}
|
||||
|
||||
// SetAvatarURL updates the avatar URL of the profile associated with the given
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package routing
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"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(
|
||||
req *http.Request, accountDB *accounts.Database, userID string,
|
||||
) (*authtypes.Profile, *util.JSONResponse) {
|
||||
|
|
@ -67,16 +69,14 @@ func getProfileByUserID(
|
|||
}
|
||||
|
||||
profile, err := accountDB.GetProfileByLocalpart(req.Context(), localpart)
|
||||
if err != nil {
|
||||
resErr := httputil.LogThenError(req, err)
|
||||
return nil, &resErr
|
||||
}
|
||||
|
||||
if profile == nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, &util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
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
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
|
|
@ -52,7 +53,12 @@ func GetProfile(
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue