From 93edea3720f32de482abe8b4a6c1d9077d1e9981 Mon Sep 17 00:00:00 2001 From: Adam Jaso <2285656+adamjaso@users.noreply.github.com> Date: Wed, 10 Oct 2018 07:20:17 -0700 Subject: [PATCH] Do not parse json on 204 responses (#476) * Do not return BadResponse for no content Signed-off-by: Adam Jaso <2285656+adamjaso@users.noreply.github.com> --- api/prometheus/v1/api.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/prometheus/v1/api.go b/api/prometheus/v1/api.go index 192ba49..6a19fac 100644 --- a/api/prometheus/v1/api.go +++ b/api/prometheus/v1/api.go @@ -477,10 +477,12 @@ func (c apiClient) Do(ctx context.Context, req *http.Request) (*http.Response, [ var result apiResponse - if err = json.Unmarshal(body, &result); err != nil { - return resp, body, &Error{ - Type: ErrBadResponse, - Msg: err.Error(), + if http.StatusNoContent != code { + if err = json.Unmarshal(body, &result); err != nil { + return resp, body, &Error{ + Type: ErrBadResponse, + Msg: err.Error(), + } } }