forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem.go
57 lines (51 loc) · 1.54 KB
/
problem.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
50
51
52
53
54
55
56
57
package bdns
import (
"fmt"
"net"
"github.com/miekg/dns"
"golang.org/x/net/context"
)
// DNSError wraps a DNS error with various relevant information
type DNSError struct {
recordType uint16
hostname string
// Exactly one of rCode or underlying should be set.
underlying error
rCode int
}
func (d DNSError) Error() string {
var detail string
if d.underlying != nil {
if netErr, ok := d.underlying.(*net.OpError); ok {
if netErr.Timeout() {
detail = detailDNSTimeout
} else {
detail = detailDNSNetFailure
}
// Note: we check d.underlying here even though `Timeout()` does this because the call to `netErr.Timeout()` above only
// happens for `*net.OpError` underlying types!
} else if d.underlying == context.Canceled || d.underlying == context.DeadlineExceeded {
detail = detailDNSTimeout
} else {
detail = detailServerFailure
}
} else if d.rCode != dns.RcodeSuccess {
detail = dns.RcodeToString[d.rCode]
} else {
detail = detailServerFailure
}
return fmt.Sprintf("DNS problem: %s looking up %s for %s", detail,
dns.TypeToString[d.recordType], d.hostname)
}
// Timeout returns true if the underlying error was a timeout
func (d DNSError) Timeout() bool {
if netErr, ok := d.underlying.(*net.OpError); ok {
return netErr.Timeout()
} else if d.underlying == context.Canceled || d.underlying == context.DeadlineExceeded {
return true
}
return false
}
const detailDNSTimeout = "query timed out"
const detailDNSNetFailure = "networking error"
const detailServerFailure = "server failure at resolver"