From 03841a01212287d93aabb14f6b3d03d88c487c81 Mon Sep 17 00:00:00 2001 From: Cnly Date: Fri, 12 Jul 2019 17:08:33 +0800 Subject: [PATCH] Better errors Signed-off-by: Alex Chen --- clientapi/routing/profile.go | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go index 192737480..4ba4e6a0e 100644 --- a/clientapi/routing/profile.go +++ b/clientapi/routing/profile.go @@ -48,13 +48,6 @@ func GetProfile( Code: http.StatusNotFound, JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), } - } else if x, ok := err.(gomatrix.HTTPError); ok { - if x.Code == http.StatusNotFound { - return util.JSONResponse{ - Code: http.StatusNotFound, - JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), - } - } } return httputil.LogThenError(req, err) @@ -82,13 +75,6 @@ func GetAvatarURL( Code: http.StatusNotFound, JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), } - } else if x, ok := err.(gomatrix.HTTPError); ok { - if x.Code == http.StatusNotFound { - return util.JSONResponse{ - Code: http.StatusNotFound, - JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), - } - } } return httputil.LogThenError(req, err) @@ -195,13 +181,6 @@ func GetDisplayName( Code: http.StatusNotFound, JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), } - } else if x, ok := err.(gomatrix.HTTPError); ok { - if x.Code == http.StatusNotFound { - return util.JSONResponse{ - Code: http.StatusNotFound, - JSON: jsonerror.NotFound("The user does not exist or does not have a profile"), - } - } } return httputil.LogThenError(req, err) @@ -295,6 +274,10 @@ func SetDisplayName( } } +// getProfile gets the full profile of a user by querying the database or a +// remote homeserver. +// Returns an error when something goes wrong or specifically +// common.ErrProfileNoExists when the profile doesn't exist. func getProfile( ctx context.Context, accountDB *accounts.Database, cfg *config.Dendrite, userID string, @@ -309,6 +292,12 @@ func getProfile( if domain != cfg.Matrix.ServerName { profile, fedErr := federation.LookupProfile(ctx, domain, userID, "") if fedErr != nil { + if x, ok := err.(gomatrix.HTTPError); ok { + if x.Code == http.StatusNotFound { + return nil, common.ErrProfileNoExists + } + } + return nil, fedErr }