-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
49 lines (39 loc) · 807 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package resolv
import (
"github.com/miekg/dns"
)
type DNSError struct {
Err string
Name string
Type uint16
Class uint16
Addr string
IsNameError bool
IsTimeout bool
}
func NewDNSError(err string, req *Request) *DNSError {
e := &DNSError{
Err: err,
Name: req.Name,
Type: req.Type,
Class: req.Class,
Addr: req.Addr,
}
return e
}
func (e *DNSError) NameError() bool { return e.IsNameError }
func (e *DNSError) Timeout() bool { return e.IsTimeout }
func (e *DNSError) Temporary() bool { return e.IsTimeout }
func (e *DNSError) Error() string {
if e == nil {
return "<nil>"
}
s := "lookup " + e.Name
s += " type " + dns.TypeToString[e.Type]
s += " class " + dns.ClassToString[e.Class]
if e.Addr != "" {
s += " on " + e.Addr
}
s += ": " + e.Err
return s
}