[MM-61077] Fix errcheck issues in server/channels/web/static.go (#29285)

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
TheoForger
2024-11-20 08:44:22 -05:00
коммит произвёл GitHub
родитель 5de425c298
Коммит 4bb4f9814b
2 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@@ -190,7 +190,6 @@ issues:
channels/utils/license_test.go|\
channels/web/oauth_test.go|\
channels/web/saml.go|\
channels/web/static.go|\
channels/web/web_test.go|\
channels/web/webhook.go|\
cmd/mattermost/commands/cmdtestlib.go|\

Просмотреть файл

@@ -64,7 +64,12 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
data := renderUnsupportedBrowser(c.AppContext, r)
c.App.Srv().TemplatesContainer().Render(w, "unsupported_browser", data)
err := c.App.Srv().TemplatesContainer().Render(w, "unsupported_browser", data)
if err != nil {
c.Logger.Error("Failed to render template", mlog.Err(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
return
}
@@ -78,7 +83,10 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) {
staticDir, _ := fileutils.FindDir(model.ClientDir)
contents, err := os.ReadFile(filepath.Join(staticDir, "root.html"))
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
c.Logger.Warn("Failed to read content from file",
mlog.String("file_path", filepath.Join(staticDir, "root.html")),
mlog.Err(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@@ -90,7 +98,11 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "text/html")
w.Write(contents)
if _, err = w.Write(contents); err != nil {
c.Logger.Warn("Failed to write content to HTTP reply", mlog.Err(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func staticFilesHandler(handler http.Handler) http.Handler {
@@ -135,7 +147,11 @@ func robotsHandler(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
}
w.Write(robotsTxt)
if _, err := w.Write(robotsTxt); err != nil {
mlog.Warn("Failed to write robots.txt", mlog.Err(err))
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func unsupportedBrowserScriptHandler(w http.ResponseWriter, r *http.Request) {