2015-10-29 00:42:05 +00:00
|
|
|
package acme
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2015-10-29 23:50:03 +00:00
|
|
|
// Error is the base type for all errors specific to the ACME protocol.
|
2015-10-29 00:42:05 +00:00
|
|
|
type Error struct {
|
|
|
|
StatusCode int `json:"status,omitempty"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Detail string `json:"detail"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Error) Error() string {
|
|
|
|
return fmt.Sprintf("[%d] Type: %s Detail: %s", e.StatusCode, e.Type, e.Detail)
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleHTTPError(resp *http.Response) error {
|
|
|
|
var errorDetail Error
|
|
|
|
decoder := json.NewDecoder(resp.Body)
|
|
|
|
err := decoder.Decode(&errorDetail)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
errorDetail.StatusCode = resp.StatusCode
|
|
|
|
return errorDetail
|
|
|
|
}
|