Merge pull request #182 from fd0/handle-non-json-response

Only try to parse JSON documents
This commit is contained in:
xenolf 2016-04-05 22:22:36 +02:00
commit 157111fd1d

View file

@ -52,10 +52,14 @@ func (c challengeError) Error() string {
func handleHTTPError(resp *http.Response) error { func handleHTTPError(resp *http.Response) error {
var errorDetail RemoteError var errorDetail RemoteError
decoder := json.NewDecoder(resp.Body)
err := decoder.Decode(&errorDetail) // try to decode the content as JSON
if err != nil { if resp.Header.Get("Content-Type") == "application/json" {
return err decoder := json.NewDecoder(resp.Body)
err := decoder.Decode(&errorDetail)
if err != nil {
return err
}
} }
errorDetail.StatusCode = resp.StatusCode errorDetail.StatusCode = resp.StatusCode