From 094e3d41bb0422746c31a8b0b2a2daeeb87408a7 Mon Sep 17 00:00:00 2001 From: xenolf Date: Fri, 15 Apr 2016 03:09:29 +0200 Subject: [PATCH] httpError - Set detail string to the content of the HTTP response if it's not parsed as JSON Fixes #188 --- acme/error.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/acme/error.go b/acme/error.go index 0d901123..2aa690b3 100644 --- a/acme/error.go +++ b/acme/error.go @@ -3,6 +3,7 @@ package acme import ( "encoding/json" "fmt" + "io/ioutil" "net/http" "strings" ) @@ -53,13 +54,21 @@ func (c challengeError) Error() string { func handleHTTPError(resp *http.Response) error { var errorDetail RemoteError + contenType := resp.Header.Get("Content-Type") // try to decode the content as JSON - if resp.Header.Get("Content-Type") == "application/json" { + if contenType == "application/json" || contenType == "application/problem+json" { decoder := json.NewDecoder(resp.Body) err := decoder.Decode(&errorDetail) if err != nil { return err } + } else { + detailBytes, err := ioutil.ReadAll(limitReader(resp.Body, 1024*1024)) + if err != nil { + return err + } + + errorDetail.Detail = string(detailBytes) } errorDetail.StatusCode = resp.StatusCode