@@ -3,6 +3,7 @@ package httpclient
33import (
44 "bytes"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "net/http"
89 "time"
@@ -62,16 +63,19 @@ func GetResponse(data any, method, url, auth string) (*http.Response, error) {
6263}
6364
6465// JSON returns JSON response from http request
65- func GetJSON [T any ](data any , resp T , method , url , auth string ) (any , error ) {
66+ func GetJSON [T any ](data any , resp T , method , url , auth string ) (any , int , error ) {
6667 response , err := GetResponse (data , method , url , auth )
6768 if err != nil {
68- return nil , err
69+ return nil , response . StatusCode , err
6970 }
7071 defer response .Body .Close ()
72+ if response .StatusCode != http .StatusOK {
73+ return response , response .StatusCode , errors .New ("non 200 response code" )
74+ }
7175 if err := json .NewDecoder (response .Body ).Decode (& resp ); err != nil {
72- return nil , err
76+ return nil , response . StatusCode , err
7377 }
74- return resp , nil
78+ return resp , response . StatusCode , nil
7579}
7680
7781// GetResponse returns response from http endpoint
@@ -80,6 +84,6 @@ func (e *Endpoint) GetResponse() (*http.Response, error) {
8084}
8185
8286// GetJSON returns JSON received from http endpoint
83- func (e * JSONEndpoint [T ]) GetJSON (response T ) (any , error ) {
87+ func (e * JSONEndpoint [T ]) GetJSON (response T ) (any , int , error ) {
8488 return GetJSON (e .Data , response , e .Method , e .URL + e .Route , e .Authorization )
8589}
0 commit comments