@@ -45,7 +45,7 @@ type httpClient interface {
4545
4646// Interface to the TeamsAPIClient
4747type Interface interface {
48- TeamInfo (teamID , token string ) (tm * Team , err error )
48+ TeamInfo (teamID , token string ) (tm * Team , statusCode int , err error )
4949}
5050
5151// API describes teams API
@@ -67,7 +67,7 @@ func NewTeamsAPI(url string, log *logrus.Entry) *API {
6767}
6868
6969// TeamInfo returns information about a given team using its ID and a token to authenticate to the API service.
70- func (t * API ) TeamInfo (teamID , token string ) (tm * Team , err error ) {
70+ func (t * API ) TeamInfo (teamID , token string ) (tm * Team , statusCode int , err error ) {
7171 var (
7272 req * http.Request
7373 resp * http.Response
@@ -77,37 +77,38 @@ func (t *API) TeamInfo(teamID, token string) (tm *Team, err error) {
7777 t .logger .Debugf ("request url: %s" , url )
7878 req , err = http .NewRequest ("GET" , url , nil )
7979 if err != nil {
80- return nil , err
80+ return nil , http . StatusBadRequest , err
8181 }
8282
8383 req .Header .Add ("Authorization" , "Bearer " + token )
8484 if resp , err = t .httpClient .Do (req ); err != nil {
85- return nil , err
85+ return nil , http . StatusUnauthorized , err
8686 }
8787 defer func () {
8888 if closeErr := resp .Body .Close (); closeErr != nil {
8989 err = fmt .Errorf ("error when closing response: %v" , closeErr )
9090 }
9191 }()
92- if resp .StatusCode != 200 {
92+ statusCode = resp .StatusCode
93+ if statusCode != http .StatusOK {
9394 var raw map [string ]json.RawMessage
9495 d := json .NewDecoder (resp .Body )
9596 err = d .Decode (& raw )
9697 if err != nil {
97- return nil , fmt .Errorf ("team API query failed with status code %d and malformed response: %v" , resp . StatusCode , err )
98+ return nil , statusCode , fmt .Errorf ("team API query failed with status code %d and malformed response: %v" , statusCode , err )
9899 }
99100
100101 if errMessage , ok := raw ["error" ]; ok {
101- return nil , fmt .Errorf ("team API query failed with status code %d and message: '%v'" , resp . StatusCode , string (errMessage ))
102+ return nil , statusCode , fmt .Errorf ("team API query failed with status code %d and message: '%v'" , statusCode , string (errMessage ))
102103 }
103- return nil , fmt .Errorf ("team API query failed with status code %d" , resp . StatusCode )
104+ return nil , statusCode , fmt .Errorf ("team API query failed with status code %d" , statusCode )
104105 }
105106
106107 tm = & Team {}
107108 d := json .NewDecoder (resp .Body )
108109 if err = d .Decode (tm ); err != nil {
109- return nil , fmt .Errorf ("could not parse team API response: %v" , err )
110+ return nil , statusCode , fmt .Errorf ("could not parse team API response: %v" , err )
110111 }
111112
112- return tm , nil
113+ return tm , statusCode , nil
113114}
0 commit comments