mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 18:23:13 -04:00 
			
		
		
		
	Remove panic/recover and also use pkg/log to print the error. This brings some consistency into the logging. Fixes #1776
		
			
				
	
	
		
			30 lines
		
	
	
		
			796 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			796 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package errors implements an HTTP error handling plugin.
 | |
| package errors
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin"
 | |
| 	clog "github.com/coredns/coredns/plugin/pkg/log"
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| // errorHandler handles DNS errors (and errors from other plugin).
 | |
| type errorHandler struct{ Next plugin.Handler }
 | |
| 
 | |
| // ServeDNS implements the plugin.Handler interface.
 | |
| func (h errorHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | |
| 	rcode, err := plugin.NextOrFailure(h.Name(), h.Next, ctx, w, r)
 | |
| 
 | |
| 	if err != nil {
 | |
| 		state := request.Request{W: w, Req: r}
 | |
| 		clog.Errorf("%d %s %s: %v", rcode, state.Name(), state.Type(), err)
 | |
| 	}
 | |
| 
 | |
| 	return rcode, err
 | |
| }
 | |
| 
 | |
| func (h errorHandler) Name() string { return "errors" }
 |