Server: Write internal server error on missing write (#57813)
This commit is contained in:
+10
-1
@@ -22,6 +22,9 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/grafana/grafana/pkg/util/errutil/errhttp"
|
||||
)
|
||||
|
||||
// Context represents the runtime context of current request of Macaron instance.
|
||||
@@ -34,6 +37,8 @@ type Context struct {
|
||||
template *template.Template
|
||||
}
|
||||
|
||||
var errMissingWrite = errutil.NewBase(errutil.StatusInternal, "web.missingWrite")
|
||||
|
||||
func (ctx *Context) run() {
|
||||
h := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||
for i := len(ctx.mws) - 1; i >= 0; i-- {
|
||||
@@ -47,7 +52,11 @@ func (ctx *Context) run() {
|
||||
// This indicates nearly always that a middleware is misbehaving and not calling its next.ServeHTTP().
|
||||
// In rare cases where a blank http.StatusOK without any body is wished, explicitly state that using w.WriteStatus(http.StatusOK)
|
||||
if !rw.Written() {
|
||||
panic("chain did not write HTTP response")
|
||||
errhttp.Write(
|
||||
ctx.Req.Context(),
|
||||
errMissingWrite.Errorf("chain did not write HTTP response: %s", ctx.Req.URL.Path),
|
||||
rw,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user