Description
Heyo!
package main
import (
"io"
"net/http"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
type Template struct {
}
func (t *Template) Render(w io.Writer, name string, data interface{}) error {
return echo.NewHTTPError(http.StatusUnauthorized)
}
func Hello(c *echo.Context) error {
return c.Render(http.StatusOK, "hello", "World")
}
func main() {
t := &Template{}
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.SetRenderer(t)
e.Get("/", Hello)
e.Run(":8080")
}
In this code example, there isn't a way to properly error out to a user in the event of a render failure. Because the c.Render
is setting http.StatusOK
, Template.Render
isn't able to propagate the error. Without calling the templates render function manually, and then piping the response of that into a c.HTML
I'm not sure of an elegant way of handling this.
Are there currently any known workarounds for this, or do you have any thoughts about how we might resolve it? Perhaps I'm just thinking incorrectly and things are working as intended? Seems like at the very least, if Template.Render
returns an error, the c.Render
should override any status message to an http.StatusInternalServerError
so a developer knows that they need to check their console?