Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
linstohu committed Dec 5, 2023
1 parent cd7061e commit f30b5eb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package utils
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
)

Expand Down Expand Up @@ -59,6 +61,16 @@ func (r *ApiResponse) ReadBody() ([]byte, error) {
buf := new(bytes.Buffer)
buf.ReadFrom(r.ApiRes.Body)

if r.ApiRes.StatusCode != http.StatusOK {
m := fmt.Sprintf("[HTTP]Failure: status code is NOT 200, %s %s, respond code=%d body=%s",
r.ApiReq.Method,
r.ApiReq.BaseURL+r.ApiReq.Path,
r.ApiRes.StatusCode,
buf.String(),
)
return nil, errors.New(m)
}

r.Body = buf.Bytes()

return r.Body, nil
Expand Down

0 comments on commit f30b5eb

Please sign in to comment.