diff --git a/gateway/assets/test/main.go b/gateway/assets/test/main.go index 8072f0000..c03074dab 100644 --- a/gateway/assets/test/main.go +++ b/gateway/assets/test/main.go @@ -157,7 +157,10 @@ func runTemplate(w http.ResponseWriter, filename string, data interface{}) { http.Error(w, fmt.Sprintf("failed to parse template file: %s", err), http.StatusInternalServerError) return } - _ = tpl.Execute(w, data) + err = tpl.Execute(w, data) + if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("error during body generation: %v", err))) + } } func main() { diff --git a/gateway/errors.go b/gateway/errors.go index 4487f0c2e..4e4bb6823 100644 --- a/gateway/errors.go +++ b/gateway/errors.go @@ -165,7 +165,7 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa if acceptsHTML { w.Header().Set("Content-Type", "text/html") w.WriteHeader(code) - _ = assets.ErrorTemplate.Execute(w, assets.ErrorTemplateData{ + err = assets.ErrorTemplate.Execute(w, assets.ErrorTemplateData{ GlobalData: assets.GlobalData{ Menu: c.Menu, }, @@ -173,6 +173,9 @@ func webError(w http.ResponseWriter, r *http.Request, c *Config, err error, defa StatusText: http.StatusText(code), Error: err.Error(), }) + if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("error during body generation: %v", err))) + } } else { http.Error(w, err.Error(), code) } diff --git a/gateway/handler.go b/gateway/handler.go index 181236b76..29a816b7a 100644 --- a/gateway/handler.go +++ b/gateway/handler.go @@ -912,11 +912,14 @@ func (i *handler) handleSuperfluousNamespace(w http.ResponseWriter, r *http.Requ // - redirects to intendedURL after a short delay w.WriteHeader(http.StatusBadRequest) - _ = redirectTemplate.Execute(w, redirectTemplateData{ + err = redirectTemplate.Execute(w, redirectTemplateData{ RedirectURL: intendedURL, SuggestedPath: intendedPath.String(), ErrorMsg: fmt.Sprintf("invalid path: %q should be %q", r.URL.Path, intendedPath.String()), }) + if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("error during body generation: %v", err))) + } return true } diff --git a/gateway/handler_codec.go b/gateway/handler_codec.go index b6a738367..89bff966e 100644 --- a/gateway/handler_codec.go +++ b/gateway/handler_codec.go @@ -203,6 +203,9 @@ func (i *handler) serveCodecHTML(ctx context.Context, w http.ResponseWriter, r * CodecHex: fmt.Sprintf("0x%x", uint64(cidCodec)), Node: parseNode(blockCid, blockData), }) + if err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("error during body generation: %v", err))) + } return err == nil } diff --git a/gateway/handler_unixfs_dir.go b/gateway/handler_unixfs_dir.go index 366514085..098a77b6a 100644 --- a/gateway/handler_unixfs_dir.go +++ b/gateway/handler_unixfs_dir.go @@ -212,6 +212,7 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r * rq.logger.Debugw("request processed", "tplDataDNSLink", globalData.DNSLink, "tplDataSize", size, "tplDataBackLink", backLink, "tplDataHash", hash) if err := assets.DirectoryTemplate.Execute(w, tplData); err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("error during body generation: %v", err))) return false }