mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-14 06:46:27 +03:00
Fix error handling and matching catch-all routes
This commit is contained in:
parent
34a25dd558
commit
5a4a1421de
2 changed files with 9 additions and 8 deletions
|
@ -31,7 +31,8 @@ func (sr ServerRoute) anyMatcherSetMatches(r *http.Request) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
// if no matchers, always match
|
||||||
|
return len(sr.matcherSets) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// MatcherSet is a set of matchers which
|
// MatcherSet is a set of matchers which
|
||||||
|
|
|
@ -65,19 +65,19 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
repl.Set("http.error.id", handlerErr.ID)
|
repl.Set("http.error.id", handlerErr.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s.Errors.Routes) == 0 {
|
if s.Errors != nil && len(s.Errors.Routes) > 0 {
|
||||||
// TODO: polish the default error handling
|
|
||||||
log.Printf("[ERROR] Handler: %s", err)
|
|
||||||
if handlerErr, ok := err.(HandlerError); ok {
|
|
||||||
w.WriteHeader(handlerErr.StatusCode)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errStack, w := s.Errors.Routes.BuildCompositeRoute(w, r)
|
errStack, w := s.Errors.Routes.BuildCompositeRoute(w, r)
|
||||||
err := s.executeCompositeRoute(w, r, errStack)
|
err := s.executeCompositeRoute(w, r, errStack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: what should we do if the error handler has an error?
|
// TODO: what should we do if the error handler has an error?
|
||||||
log.Printf("[ERROR] handling error: %v", err)
|
log.Printf("[ERROR] handling error: %v", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: polish the default error handling
|
||||||
|
log.Printf("[ERROR] Handler: %s", err)
|
||||||
|
if handlerErr, ok := err.(HandlerError); ok {
|
||||||
|
w.WriteHeader(handlerErr.StatusCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue