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 }