package acme import ( "encoding/json" "errors" "fmt" "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 Errors = map[string]error{ "badCSR": errBadCSR, "badNonce": errBadNonce, "connection": errConnection, "dnssec": errDnssec, "malformed": errMalformed, "serverInternal": errServerInternal, "tls": errTLS, "unauthorized": errUnauthorized, "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 } if e, ok := Errors["urn:acme:error"+p.Type]; ok { return fmt.Errorf("%v: %v", e, p.Detail) } return errors.New(p.Detail) }