@marcel91200 / caddy Mirror · read-only / commits / 349457cc
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddyhttp: Return error if error handling error

Before, if there was an error in the error handler, we would not write a status code, which resulted in Go writing a 200 for us by default, which does not make sense when there's an error. Now we write the second error's status if available, otherwise 500.

Matthew Holt committed Nov 18, 2020 at 16:14 UTC 349457cc1b386e92b348846a354807d6ceeb81df
1 file changed +5
modules/caddyhttp/server.go
+5
@@ -247,6 +247,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
247 zap.String("msg", errMsg),
248 }, errFields...)
249 logger.Error("error handling handler error", errFields...)
250 + if handlerErr, ok := err.(HandlerError); ok {
251 + w.WriteHeader(handlerErr.StatusCode)
252 + } else {
253 + w.WriteHeader(http.StatusInternalServerError)
254 + }
255 }
256 } else {
257 if errStatus >= 500 {