forked from TrueCloudLab/lego
httpError - Set detail string to the content of the HTTP response if it's not parsed as JSON
Fixes #188
This commit is contained in:
parent
cbca761215
commit
094e3d41bb
1 changed files with 10 additions and 1 deletions
|
@ -3,6 +3,7 @@ package acme
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -53,13 +54,21 @@ func (c challengeError) Error() string {
|
||||||
func handleHTTPError(resp *http.Response) error {
|
func handleHTTPError(resp *http.Response) error {
|
||||||
var errorDetail RemoteError
|
var errorDetail RemoteError
|
||||||
|
|
||||||
|
contenType := resp.Header.Get("Content-Type")
|
||||||
// try to decode the content as JSON
|
// 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)
|
decoder := json.NewDecoder(resp.Body)
|
||||||
err := decoder.Decode(&errorDetail)
|
err := decoder.Decode(&errorDetail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
errorDetail.StatusCode = resp.StatusCode
|
||||||
|
|
Loading…
Reference in a new issue