Skip to content

Commit

Permalink
Merge pull request #26 from Snawoot/holaapi_req_2xx
Browse files Browse the repository at this point in the history
hola: expect only 2xx responses
  • Loading branch information
Snawoot authored Mar 12, 2021
2 parents 6ced446 + 95adb40 commit be2e4e5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions holaapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"github.com/campoy/unique"
"github.com/google/uuid"
"io/ioutil"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit be2e4e5

Please sign in to comment.