diff --git a/server/api.go b/server/api.go index 69c4eebd..7f08d418 100644 --- a/server/api.go +++ b/server/api.go @@ -137,7 +137,7 @@ func (p *Plugin) withRecovery(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { if x := recover(); x != nil { - p.API.LogError("Recovered from a panic", + p.API.LogWarn("Recovered from a panic", "url", r.URL.String(), "error", x, "stack", string(debug.Stack())) @@ -171,7 +171,7 @@ func (p *Plugin) checkAuth(handler http.HandlerFunc, responseType ResponseType) case ResponseTypePlain: http.Error(w, "Not authorized", http.StatusUnauthorized) default: - p.API.LogError("Unknown ResponseType detected") + p.API.LogDebug("Unknown ResponseType detected") } return } @@ -204,18 +204,18 @@ func (p *Plugin) writeAPIError(w http.ResponseWriter, err *APIErrorResponse) { b, _ := json.Marshal(err) w.WriteHeader(err.StatusCode) if _, err := w.Write(b); err != nil { - p.API.LogError("can't write api error http response", "err", err.Error()) + p.API.LogWarn("can't write api error http response", "err", err.Error()) } } func (p *Plugin) writeAPIResponse(w http.ResponseWriter, resp interface{}) { b, jsonErr := json.Marshal(resp) if jsonErr != nil { - p.API.LogError("Error encoding JSON response", "err", jsonErr.Error()) + p.API.LogWarn("Error encoding JSON response", "err", jsonErr.Error()) p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Encountered an unexpected error. Please try again.", StatusCode: http.StatusInternalServerError}) } if _, err := w.Write(b); err != nil { - p.API.LogError("can't write response user to http", "err", err.Error()) + p.API.LogWarn("can't write response user to http", "err", err.Error()) p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Encountered an unexpected error. Please try again.", StatusCode: http.StatusInternalServerError}) } } @@ -645,7 +645,7 @@ func (p *Plugin) getChannelSubscriptions(c *UserContext, w http.ResponseWriter, config := p.getConfiguration() subscriptions, err := p.GetSubscriptionsByChannel(channelID) if err != nil { - p.API.LogError("unable to get subscriptions by channel", "err", err.Error()) + p.API.LogWarn("unable to get subscriptions by channel", "err", err.Error()) p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Unable to get subscriptions by channel.", StatusCode: http.StatusInternalServerError}) return } @@ -654,9 +654,9 @@ func (p *Plugin) getChannelSubscriptions(c *UserContext, w http.ResponseWriter, b, err := json.Marshal(resp) if err != nil { - p.API.LogError("failed to marshal channel subscriptions response", "err", err.Error()) + p.API.LogWarn("failed to marshal channel subscriptions response", "err", err.Error()) p.writeAPIError(w, &APIErrorResponse{ID: "", Message: "Encountered an unexpected error. Please try again.", StatusCode: http.StatusInternalServerError}) } else if _, err := w.Write(b); err != nil { - p.API.LogError("can't write api error http response", "err", err.Error()) + p.API.LogWarn("can't write api error http response", "err", err.Error()) } } diff --git a/server/cluster.go b/server/cluster.go index a6f8ae5e..e77788af 100644 --- a/server/cluster.go +++ b/server/cluster.go @@ -38,8 +38,6 @@ func (p *Plugin) sendMessageToCluster(id string, v interface{}) { } func (p *Plugin) HandleClusterEvent(ev model.PluginClusterEvent) { - p.API.LogError("received cluster event", "id", ev.Id) - switch ev.Id { case oauthCompleteEventID: var event OAuthCompleteEvent diff --git a/server/command.go b/server/command.go index b33deaf5..fb82505f 100644 --- a/server/command.go +++ b/server/command.go @@ -219,7 +219,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo case "todo": _, text, err := p.GetToDo(ctx, info) if err != nil { - p.API.LogError("can't get todo in command", "err", err.Error()) + p.API.LogWarn("can't get todo in command", "err", err.Error()) return p.getCommandResponse(args, "Encountered an error getting your to do items."), nil } return p.getCommandResponse(args, text), nil @@ -249,15 +249,15 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo case SettingNotifications: if value { if err := p.storeGitlabToUserIDMapping(info.GitlabUsername, info.UserID); err != nil { - p.API.LogError("can't store GitLab to user id mapping", "err", err.Error()) + p.API.LogWarn("can't store GitLab to user id mapping", "err", err.Error()) return p.getCommandResponse(args, "Unknown error please retry or ask to an administrator to look at logs"), nil } if err := p.storeGitlabIDToUserIDMapping(info.GitlabUsername, info.GitlabUserID); err != nil { - p.API.LogError("can't store GitLab to GitLab id mapping", "err", err.Error()) + p.API.LogWarn("can't store GitLab to GitLab id mapping", "err", err.Error()) return p.getCommandResponse(args, "Unknown error please retry or ask to an administrator to look at logs"), nil } } else if err := p.deleteGitlabToUserIDMapping(info.GitlabUsername); err != nil { - p.API.LogError("can't delete GitLab username in kvstore", "err", err.Error()) + p.API.LogWarn("can't delete GitLab username in kvstore", "err", err.Error()) return p.getCommandResponse(args, "Unknown error please retry or ask to an administrator to look at logs"), nil } info.Settings.Notifications = value @@ -268,7 +268,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo } if err := p.storeGitlabUserInfo(info); err != nil { - p.API.LogError("can't store user info after update by command", "err", err.Error()) + p.API.LogWarn("can't store user info after update by command", "err", err.Error()) return p.getCommandResponse(args, "Unknown error please retry or ask to an administrator to look at logs"), nil } @@ -484,7 +484,7 @@ func (p *Plugin) subscriptionDelete(info *gitlab.UserInfo, config *configuration normalizedPath := normalizePath(fullPath, config.GitlabURL) deleted, err := p.Unsubscribe(channelID, normalizedPath) if err != nil { - p.API.LogError("can't unsubscribe channel in command", "err", err.Error()) + p.API.LogWarn("can't unsubscribe channel in command", "err", err.Error()) return "Encountered an error trying to unsubscribe. Please try again.", nil } @@ -528,7 +528,7 @@ func (p *Plugin) subscriptionsAddCommand(ctx context.Context, info *gitlab.UserI } else if errors.Is(err, gitlab.ErrPrivateResource) { return "Requested resource is private." } - p.API.LogError( + p.API.LogWarn( "unable to resolve subscription namespace and project name", "err", err.Error(), ) @@ -536,7 +536,7 @@ func (p *Plugin) subscriptionsAddCommand(ctx context.Context, info *gitlab.UserI } if subscribeErr := p.Subscribe(info, namespace, project, channelID, features); subscribeErr != nil { - p.API.LogError( + p.API.LogWarn( "failed to subscribe", "namespace", namespace, "project", project, diff --git a/server/plugin.go b/server/plugin.go index bf9698bb..0275cc2e 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -267,7 +267,7 @@ func (p *Plugin) getGitlabUserInfoByMattermostID(userID string) (*gitlab.UserInf unencryptedToken, err := decrypt([]byte(config.EncryptionKey), userInfo.Token.AccessToken) if err != nil { - p.API.LogError("can't decrypt token", "err", err.Error()) + p.API.LogWarn("can't decrypt token", "err", err.Error()) return nil, &APIErrorResponse{ID: "", Message: "Unable to decrypt access token.", StatusCode: http.StatusInternalServerError} } @@ -321,7 +321,7 @@ func (p *Plugin) deleteGitlabIDToUserIDMapping(gitlabID int) error { func (p *Plugin) getGitlabToUserIDMapping(gitlabUsername string) string { userID, err := p.API.KVGet(gitlabUsername + GitlabUsernameKey) if err != nil { - p.API.LogError("can't get userId from store with username", "err", err.DetailedError, "username", gitlabUsername) + p.API.LogWarn("can't get userId from store with username", "err", err.DetailedError, "username", gitlabUsername) } return string(userID) } @@ -329,7 +329,7 @@ func (p *Plugin) getGitlabToUserIDMapping(gitlabUsername string) string { func (p *Plugin) getGitlabIDToUsernameMapping(gitlabUserID string) string { gitlabUsername, err := p.API.KVGet(gitlabUserID + GitlabIDUsernameKey) if err != nil { - p.API.LogError("can't get user id by login", "err", err.DetailedError) + p.API.LogWarn("can't get user id by login", "err", err.DetailedError) } return string(gitlabUsername) } @@ -337,7 +337,7 @@ func (p *Plugin) getGitlabIDToUsernameMapping(gitlabUserID string) string { func (p *Plugin) disconnectGitlabAccount(userID string) { userInfo, err := p.getGitlabUserInfoByMattermostID(userID) if err != nil { - p.API.LogError("can't get GitLab user info from mattermost id", "err", err.Message) + p.API.LogWarn("can't get GitLab user info from mattermost id", "err", err.Message) return } if userInfo == nil { @@ -345,19 +345,19 @@ func (p *Plugin) disconnectGitlabAccount(userID string) { } if err := p.deleteGitlabUserInfo(userID); err != nil { - p.API.LogError("can't delete token in store", "err", err.Error, "userId", userID) + p.API.LogWarn("can't delete token in store", "err", err.Error, "userId", userID) } if err := p.deleteGitlabToUserIDMapping(userInfo.GitlabUsername); err != nil { - p.API.LogError("can't delete username in store", "err", err.Error, "username", userInfo.GitlabUsername) + p.API.LogWarn("can't delete username in store", "err", err.Error, "username", userInfo.GitlabUsername) } if err := p.deleteGitlabIDToUserIDMapping(userInfo.GitlabUserID); err != nil { - p.API.LogError("can't delete user id in store", "err", err.Error, "id", userInfo.GitlabUserID) + p.API.LogWarn("can't delete user id in store", "err", err.Error, "id", userInfo.GitlabUserID) } if user, err := p.API.GetUser(userID); err == nil && user.Props != nil && len(user.Props["git_user"]) > 0 { delete(user.Props, "git_user") if _, err := p.API.UpdateUser(user); err != nil { - p.API.LogError("can't update user after delete git account", "err", err.DetailedError) + p.API.LogWarn("can't update user after delete git account", "err", err.DetailedError) } } @@ -383,7 +383,7 @@ func (p *Plugin) registerChimeraURL() { func (p *Plugin) CreateBotDMPost(userID, message, postType string) *model.AppError { channel, err := p.API.GetDirectChannel(userID, p.BotUserID) if err != nil { - p.API.LogError("Couldn't get bot's DM channel", "user_id", userID) + p.API.LogWarn("Couldn't get bot's DM channel", "user_id", userID) return err } @@ -395,7 +395,7 @@ func (p *Plugin) CreateBotDMPost(userID, message, postType string) *model.AppErr } if _, err := p.API.CreatePost(post); err != nil { - p.API.LogError("can't post DM", "err", err.DetailedError) + p.API.LogWarn("can't post DM", "err", err.DetailedError) return err } @@ -405,7 +405,7 @@ func (p *Plugin) CreateBotDMPost(userID, message, postType string) *model.AppErr func (p *Plugin) PostToDo(ctx context.Context, info *gitlab.UserInfo) { hasTodo, text, err := p.GetToDo(ctx, info) if err != nil { - p.API.LogError("can't post todo", "err", err.Error()) + p.API.LogWarn("can't post todo", "err", err.Error()) return } if !hasTodo { @@ -413,7 +413,7 @@ func (p *Plugin) PostToDo(ctx context.Context, info *gitlab.UserInfo) { } if err := p.CreateBotDMPost(info.UserID, text, "custom_git_todo"); err != nil { - p.API.LogError("can't create dm post in post todo", "err", err.DetailedError) + p.API.LogWarn("can't create dm post in post todo", "err", err.DetailedError) } } diff --git a/server/subscriptions.go b/server/subscriptions.go index a4ba19a1..55da53c2 100644 --- a/server/subscriptions.go +++ b/server/subscriptions.go @@ -88,7 +88,7 @@ func (p *Plugin) GetSubscriptions() (*Subscriptions, error) { value, err := p.API.KVGet(SubscriptionsKey) if err != nil { - p.API.LogError("can't get subscriptions from kvstore", "err", err.DetailedError) + p.API.LogWarn("can't get subscriptions from kvstore", "err", err.DetailedError) return nil, err } @@ -107,7 +107,7 @@ func (p *Plugin) StoreSubscriptions(s *Subscriptions) error { return err } if err := p.API.KVSet(SubscriptionsKey, b); err != nil { - p.API.LogError("can't set subscriptions in kvstore", "err", err.DetailedError) + p.API.LogWarn("can't set subscriptions in kvstore", "err", err.DetailedError) } return nil } @@ -122,7 +122,7 @@ func (p *Plugin) GetSubscribedChannelsForProject( subs, err := p.GetSubscriptions() if err != nil { - p.API.LogError("can't retrieve subscriptions", "err", err.Error()) + p.API.LogWarn("can't retrieve subscriptions", "err", err.Error()) return nil } diff --git a/server/webhook.go b/server/webhook.go index e693f7dd..333b9886 100644 --- a/server/webhook.go +++ b/server/webhook.go @@ -155,12 +155,12 @@ func (p *Plugin) handleWebhook(w http.ResponseWriter, r *http.Request) { if len(userTo) > 0 && len(res.Message) > 0 { info, err := p.getGitlabUserInfoByMattermostID(userTo) if err != nil { - p.API.LogError("can't get user info to know if user wants to receive notifications", "err", err.Message) + p.API.LogWarn("can't get user info to know if user wants to receive notifications", "err", err.Message) continue } if info.Settings.Notifications { if err := p.CreateBotDMPost(userTo, res.Message, "custom_git_review_request"); err != nil { - p.API.LogError("can't send dm post", "err", err.Error()) + p.API.LogWarn("can't send dm post", "err", err.Error()) } } } @@ -173,7 +173,7 @@ func (p *Plugin) handleWebhook(w http.ResponseWriter, r *http.Request) { ChannelId: to, } if _, err := p.API.CreatePost(post); err != nil { - p.API.LogError("can't create post for webhook event", "err", err.Error()) + p.API.LogWarn("can't create post for webhook event", "err", err.Error()) } } } @@ -209,7 +209,7 @@ func (p *Plugin) permissionToProject(ctx context.Context, userID, namespace, pro if result, err := p.GitlabClient.GetProject(ctx, info, namespace, project); result == nil || err != nil { if err != nil { - p.API.LogError("can't get project in webhook", "err", err.Error(), "project", namespace+"/"+project) + p.API.LogWarn("can't get project in webhook", "err", err.Error(), "project", namespace+"/"+project) } return false }