blob: eb486bde1ee9c8eb6e1dcde729b58c1d33e57df4 (
plain)
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
|
package acme
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
)
var (
errBadCSR = errors.New("The CSR is unacceptable (e.g., due to a short key)")
errBadNonce = errors.New("The client sent an unacceptable anti-replay nonce")
errConnection = errors.New("The server could not connect to the client for DV")
errDnssec = errors.New("The server could not validate a DNSSEC signed domain")
errMalformed = errors.New("The request message was malformed")
errServerInternal = errors.New("The server experienced an internal error")
errTLS = errors.New("The server experienced a TLS error during DV")
errUnauthorized = errors.New("The client lacks sufficient authorization")
errUnknownHost = errors.New("The server could not resolve a domain name")
)
// Errors
var urnErrors = map[string]error{
"urn:acme:error:badCSR": errBadCSR,
"urn:acme:error:badNonce": errBadNonce,
"urn:acme:error:connection": errConnection,
"urn:acme:error:dnssec": errDnssec,
"urn:acme:error:malformed": errMalformed,
"urn:acme:error:serverInternal": errServerInternal,
"urn:acme:error:tls": errTLS,
"urn:acme:error:unauthorized": errUnauthorized,
"urn:acme:error:unknownHost": errUnknownHost,
}
func handleError(r *http.Response) error {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
var p Problem
err = json.Unmarshal(body, &p)
if err != nil {
return err
}
return p
}
func (p Problem) Error() string {
if err, ok := urnErrors[p.Type]; ok {
return err.Error() + ": " + p.Detail
}
return p.Detail
}
|