From 95adb40377b94686a1a45ecefe15d2eaeb2ac985 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Fri, 12 Mar 2021 22:27:31 +0200 Subject: [PATCH] hola: expect only 2xx responses --- holaapi.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/holaapi.go b/holaapi.go index 2640505..f207696 100644 --- a/holaapi.go +++ b/holaapi.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "fmt" "github.com/campoy/unique" "github.com/google/uuid" "io/ioutil" @@ -87,6 +88,11 @@ func do_req(ctx context.Context, method, url string, query, data url.Values) ([] if err != nil { return nil, err } + switch resp.StatusCode { + case http.StatusOK, http.StatusCreated, http.StatusAccepted, http.StatusNoContent: + default: + return nil, errors.New(fmt.Sprintf("Bad HTTP response: %d %s", resp.StatusCode, resp.Status)) + } body, err := ioutil.ReadAll(resp.Body) resp.Body.Close() if err != nil {