From cb0df3ebbc1b2fd6985ed2542255486b108f33f0 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 7 Apr 2021 14:56:44 +0200 Subject: [PATCH] Show empty avatar when the user was not found --- pkg/routes/api/v1/avatar.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/routes/api/v1/avatar.go b/pkg/routes/api/v1/avatar.go index 488eb0e9..03c9e057 100644 --- a/pkg/routes/api/v1/avatar.go +++ b/pkg/routes/api/v1/avatar.go @@ -62,14 +62,13 @@ func GetAvatar(c echo.Context) error { // Get the user u, err := user.GetUserWithEmail(s, &user.User{Username: username}) - if err != nil { + if err != nil && !user.IsErrUserDoesNotExist(err) { log.Errorf("Error getting user for avatar: %v", err) return handler.HandleHTTPError(err, c) } - // Initialize the avatar provider - // For now, we only have one avatar provider, in the future there could be multiple which - // could be changed based on user settings etc. + found := !(err != nil && user.IsErrUserDoesNotExist(err)) + var avatarProvider avatar.Provider switch u.AvatarProvider { case "gravatar": @@ -82,6 +81,10 @@ func GetAvatar(c echo.Context) error { avatarProvider = &empty.Provider{} } + if !found { + avatarProvider = &empty.Provider{} + } + size := c.QueryParam("size") var sizeInt int64 = 250 // Default size of 250 if size != "" {