mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Add middleware.NextOrFailure (#462)
This checks if the next middleware to be called is nil, and if so returns ServerFailure and an error. This makes the next calling more robust and saves some lines of code. Also prefix the error with the name of the middleware to aid in debugging.
This commit is contained in:
@@ -44,7 +44,7 @@ type (
|
||||
func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := request.Request{W: w, Req: r}
|
||||
if state.QClass() != dns.ClassINET {
|
||||
return dns.RcodeServerFailure, errors.New("can only deal with ClassINET")
|
||||
return dns.RcodeServerFailure, middleware.Error(a.Name(), errors.New("can only deal with ClassINET"))
|
||||
}
|
||||
qname := state.Name()
|
||||
|
||||
@@ -53,10 +53,7 @@ func (a Auto) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||
// Precheck with the origins, i.e. are we allowed to looks here.
|
||||
zone := middleware.Zones(a.Zones.Origins()).Matches(qname)
|
||||
if zone == "" {
|
||||
if a.Next != nil {
|
||||
return a.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
return dns.RcodeServerFailure, errors.New("no next middleware found")
|
||||
return middleware.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||
}
|
||||
|
||||
// Now the real zone.
|
||||
|
||||
Reference in New Issue
Block a user