Errcheck issues fixed in server/channels/api4/brand.go (#28362)

* errcheck proper error handling

* write response err check log

* resolving conflicts and io.Copy error handling
This commit is contained in:
Arya Khochare 2024-10-09 22:13:34 +05:30 committed by GitHub
parent ce63a20980
commit ac38f5f751
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -61,7 +61,6 @@ issues:
path: "\
channels/api4/apitestlib.go|\
channels/api4/bot_test.go|\
channels/api4/brand.go|\
channels/api4/channel.go|\
channels/api4/channel_test.go|\
channels/api4/cloud.go|\

View File

@ -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/audit"
)
@ -23,16 +24,24 @@ func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
img, err := c.App.GetBrandImage(c.AppContext)
if err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write(nil)
if _, err := w.Write(nil); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
return
}
w.Header().Set("Content-Type", "image/png")
w.Write(img)
if _, err := w.Write(img); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
defer io.Copy(io.Discard, r.Body)
defer func() {
if _, err := io.Copy(io.Discard, r.Body); err != nil {
c.Logger.Warn("Error discarding request body", mlog.Err(err))
}
}()
if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize {
c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)