diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2015-12-05 18:34:14 +0100 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2015-12-05 18:34:14 +0100 |
commit | 41b3e1bf504c1dd54046ece9a79b6095ac7e4621 (patch) | |
tree | ab7e919050ffd2517ac0f3f105cc238d9e6a4637 | |
parent | bbe2bd0eb1f26d01a1c785db11339c4e1d3b4445 (diff) |
Play with errors
-rw-r--r-- | errors.go | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -3,7 +3,6 @@ package acme import ( "encoding/json" "errors" - "fmt" "io/ioutil" "net/http" ) @@ -22,15 +21,15 @@ var ( // Errors var urnErrors = map[string]error{ - "badCSR": ErrBadCSR, - "badNonce": ErrBadNonce, - "connection": ErrConnection, - "dnssec": ErrDnssec, - "malformed": ErrMalformed, - "serverInternal": ErrServerInternal, - "tls": ErrTLS, - "unauthorized": ErrUnauthorized, - "unknownHost": ErrUnknownHost, + "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 { @@ -44,8 +43,12 @@ func handleError(r *http.Response) error { if err != nil { return err } - if e, ok := urnErrors["urn:acme:error"+p.Type]; ok { - return fmt.Errorf("%v: %v", e, p.Detail) + return p +} + +func (p Problem) Error() string { + if err, ok := urnErrors[p.Type]; ok { + return err.Error() + ": " + p.Detail } - return errors.New(p.Detail) + return p.Detail } |