aboutsummaryrefslogtreecommitdiff
path: root/errors.go
diff options
context:
space:
mode:
Diffstat (limited to 'errors.go')
-rw-r--r--errors.go25
1 files changed, 24 insertions, 1 deletions
diff --git a/errors.go b/errors.go
index f23aae3..a321863 100644
--- a/errors.go
+++ b/errors.go
@@ -1,6 +1,12 @@
package acme
-import "errors"
+import (
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+)
var (
errBadCSR = errors.New("The CSR is unacceptable (e.g., due to a short key)")
@@ -26,3 +32,20 @@ var Errors = map[string]error{
"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
+ }
+ if e, ok := Errors[p.Type]; ok {
+ return fmt.Errorf("%v: %v", e, p.Detail)
+ }
+ return errors.New(p.Detail)
+}