Skip to content

Commit

Permalink
move http code check
Browse files Browse the repository at this point in the history
  • Loading branch information
hurngchunlee committed Mar 12, 2019
1 parent 01a3200 commit 10b23da
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *WebhookConfig) New(script string) (*url.URL, error) {

log.Debugf("response data: %+v", response)

if err != nil || httpCode != 200 {
if err != nil {
return nil, fmt.Errorf("error registering webhook on QaaS server: +%v (HTTP CODE: %d)", err, httpCode)
}

Expand Down Expand Up @@ -206,8 +206,8 @@ func (s *WebhookConfig) GetInfo(id string) (WebhookConfigInfo, error) {

log.Debugf("response data: %+v", response)

if err != nil || httpCode != 200 {
return info, fmt.Errorf("error retrieving webhook info from the QaaS server: +%v (HTTP CODE: %d)", err, httpCode)
if err != nil {
return info, fmt.Errorf("error retrieving webhook info from the QaaS server: %+v (HTTP CODE: %d)", err, httpCode)
}

if id != response.Webhook.Hash {
Expand Down Expand Up @@ -321,6 +321,10 @@ func (s *WebhookConfig) httpPutJSON(url *url.URL, request interface{}, response
}
defer rsp.Body.Close()

if rsp.StatusCode != 200 {
return rsp.StatusCode, fmt.Errorf("%s", rsp.Status)
}

return rsp.StatusCode, json.NewDecoder(rsp.Body).Decode(response)
}

Expand Down Expand Up @@ -361,6 +365,10 @@ func (s *WebhookConfig) httpGetJSON(url *url.URL, request interface{}, response
}
defer rsp.Body.Close()

if rsp.StatusCode != 200 {
return rsp.StatusCode, fmt.Errorf("%s", rsp.Status)
}

return rsp.StatusCode, json.NewDecoder(rsp.Body).Decode(response)
}

Expand Down Expand Up @@ -388,6 +396,10 @@ func (s *WebhookConfig) httpDelete(url *url.URL, request interface{}) (int, erro
}
defer rsp.Body.Close()

if rsp.StatusCode != 200 {
return rsp.StatusCode, fmt.Errorf("%s", rsp.Status)
}

return rsp.StatusCode, nil
}

Expand Down

0 comments on commit 10b23da

Please sign in to comment.