From b8b3f9b012871d9ffcc2802a7f8bea27e91bc04c Mon Sep 17 00:00:00 2001 From: CarlssonFilip <123748780+CarlssonFilip@users.noreply.github.com> Date: Mon, 7 Oct 2024 21:03:12 +0200 Subject: [PATCH] [GH-28396] Fixed errcheck issues in server/channels/api4/ip_filtering.go (#28441) * Fixed errcheck issues in server/channels/api4/ip_filtering.go * Added separate go routine to SendIPFiltersChangedEmail and removed redundant return * Added import for mlog * Changed from returning error to logging it --------- Co-authored-by: Ben Schumacher --- server/.golangci.yml | 1 - server/channels/api4/ip_filtering.go | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 82e8e840622..304130ac818 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -82,7 +82,6 @@ issues: channels/api4/handlers_test.go|\ channels/api4/import_test.go|\ channels/api4/integration_action_test.go|\ - channels/api4/ip_filtering.go|\ channels/api4/ip_filtering_test.go|\ channels/api4/job_test.go|\ channels/api4/license.go|\ diff --git a/server/channels/api4/ip_filtering.go b/server/channels/api4/ip_filtering.go index a7c45cef662..62ab0bab0fb 100644 --- a/server/channels/api4/ip_filtering.go +++ b/server/channels/api4/ip_filtering.go @@ -8,6 +8,7 @@ import ( "net/http" "github.com/mattermost/mattermost/server/public/model" + "github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/v8/channels/app" "github.com/mattermost/mattermost/server/v8/channels/audit" "github.com/mattermost/mattermost/server/v8/einterfaces" @@ -81,7 +82,11 @@ func applyIPFilters(c *Context, w http.ResponseWriter, r *http.Request) { auditRec.Success() - go c.App.SendIPFiltersChangedEmail(c.AppContext, c.AppContext.Session().UserId) + go func() { + if err := c.App.SendIPFiltersChangedEmail(c.AppContext, c.AppContext.Session().UserId); err != nil { + c.Logger.Warn("Failed to send IP filters changed email", mlog.Err(err)) + } + }() if err := json.NewEncoder(w).Encode(updatedAllowedRanges); err != nil { c.Err = model.NewAppError("getIPFilters", "api.context.ip_filtering.get_ip_filters.app_error", nil, "", http.StatusInternalServerError).Wrap(err) @@ -106,5 +111,7 @@ func myIP(c *Context, w http.ResponseWriter, r *http.Request) { return } - w.Write(json) + if _, err := w.Write(json); err != nil { + c.Logger.Warn("Error while writing response", mlog.Err(err)) + } }