Skip to content

Commit

Permalink
[MM-61077] Fix errcheck issues in server/channels/web/static.go (matt…
Browse files Browse the repository at this point in the history
…ermost#29285)

Co-authored-by: Ben Schumacher <[email protected]>
  • Loading branch information
theoforger and hanzei authored Nov 20, 2024
1 parent 5de425c commit 4bb4f98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 0 additions & 1 deletion server/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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|\
Expand Down
24 changes: 20 additions & 4 deletions server/channels/web/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4bb4f98

Please sign in to comment.