summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-11-18 16:14:50 -0700
committerMatthew Holt <mholt@users.noreply.github.com>2020-11-18 16:14:50 -0700
commit349457cc1b386e92b348846a354807d6ceeb81df (patch)
tree1394f5cdbafbefae72b27b710f26e013ab4f2234 /modules
parent1438e4dbc83353166f30978cf471f05e6c0ecd73 (diff)
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.
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/server.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index d5be1e1..cff0f2e 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -247,6 +247,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
zap.String("msg", errMsg),
}, errFields...)
logger.Error("error handling handler error", errFields...)
+ if handlerErr, ok := err.(HandlerError); ok {
+ w.WriteHeader(handlerErr.StatusCode)
+ } else {
+ w.WriteHeader(http.StatusInternalServerError)
+ }
}
} else {
if errStatus >= 500 {