Skip to content

Commit

Permalink
check response http status code
Browse files Browse the repository at this point in the history
  • Loading branch information
backguynn committed Dec 12, 2023
1 parent e1cb1b8 commit dbb8007
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,17 @@ func (m *Manager) deleteLoadBalancer(ns, name string) error {
}(loxiClient, ch)
}

var err error
isError := true
for _, errCh := range errChList {
err := <-errCh
err = <-errCh
if err == nil {
isError = false
break
}
}
if isError {
return fmt.Errorf("failed to delete loxiLB LoadBalancer")
return fmt.Errorf("failed to delete loxiLB LoadBalancer. err: %v", err)
}
if lb.inRange {
ipPool.ReturnIPAddr(lb.LbModel.Service.ExternalIP, lb.IdentIPAM)
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,26 @@ func (l *LoxiRequest) Do(ctx context.Context) *LoxiResponse {

resp, err := l.client.Client.Do(req)
if err != nil {
return &LoxiResponse{err: err}
statusCode := 0
if resp != nil {
statusCode = resp.StatusCode
}
return &LoxiResponse{statusCode: statusCode, err: err}
}

defer resp.Body.Close()
respByte, err := io.ReadAll(resp.Body)
if err != nil {
return &LoxiResponse{err: err}
return &LoxiResponse{statusCode: resp.StatusCode, err: err}
}

if resp.StatusCode == http.StatusOK {
if err := json.Unmarshal(respByte, &result); err != nil {
return &LoxiResponse{err: err}
return &LoxiResponse{statusCode: resp.StatusCode, err: err}
}

if result.Result != "Success" {
return &LoxiResponse{err: errors.New(result.Result)}
return &LoxiResponse{statusCode: resp.StatusCode, err: errors.New(result.Result)}
}
}

Expand Down

0 comments on commit dbb8007

Please sign in to comment.