Skip to content

Commit

Permalink
Merge pull request #22 from ConductorOne/ggreer/resp-nil
Browse files Browse the repository at this point in the history
Handle case of resp possibly being nil due.
  • Loading branch information
ggreer authored Jul 30, 2024
2 parents b7272ac + 7348b33 commit 493afd4
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,16 @@ func (d *DataCenterClient) CachedGet(ctx context.Context, req *http.Request, opt
l.Debug("cache miss", zap.String("cacheKey", cacheKey))
resp, err := d.httpClient.Do(req, options...)
if err != nil {
return nil, &BitbucketError{
bbErr := &BitbucketError{
ErrorMessage: err.Error(),
ErrorDescription: err.Error(),
ErrorCode: resp.StatusCode,
ErrorSummary: fmt.Sprint(resp.Body),
ErrorLink: req.URL.String(),
}
if resp != nil {
bbErr.ErrorCode = resp.StatusCode
bbErr.ErrorSummary = fmt.Sprint(resp.Body)
}
return nil, bbErr
}

d.bitbucketCache.Set(cacheKey, resp)
Expand Down Expand Up @@ -1209,13 +1212,16 @@ func (d *DataCenterClient) UpdateGroupRepositoryPermission(ctx context.Context,

resp, err := d.httpClient.Do(req)
if err != nil {
return &BitbucketError{
bbErr := &BitbucketError{
ErrorMessage: err.Error(),
ErrorDescription: err.Error(),
ErrorCode: resp.StatusCode,
ErrorSummary: fmt.Sprint(resp.Body),
ErrorLink: endpointUrl,
}
if resp != nil {
bbErr.ErrorCode = resp.StatusCode
bbErr.ErrorSummary = fmt.Sprint(resp.Body)
}
return bbErr
}

defer resp.Body.Close()
Expand Down Expand Up @@ -1373,13 +1379,16 @@ func (d *DataCenterClient) RevokeGroupProjectPermission(ctx context.Context, pro

resp, err := d.httpClient.Do(req)
if err != nil {
return &BitbucketError{
bbErr := &BitbucketError{
ErrorMessage: err.Error(),
ErrorDescription: err.Error(),
ErrorCode: resp.StatusCode,
ErrorSummary: fmt.Sprint(resp.Body),
ErrorLink: endpointUrl,
}
if resp != nil {
bbErr.ErrorCode = resp.StatusCode
bbErr.ErrorSummary = fmt.Sprint(resp.Body)
}
return bbErr
}

defer resp.Body.Close()
Expand Down Expand Up @@ -1459,13 +1468,16 @@ func (d *DataCenterClient) UpdateGroupProjectPermission(ctx context.Context, pro

resp, err := d.httpClient.Do(req)
if err != nil {
return &BitbucketError{
bbErr := &BitbucketError{
ErrorMessage: err.Error(),
ErrorDescription: err.Error(),
ErrorCode: resp.StatusCode,
ErrorSummary: fmt.Sprint(resp.Body),
ErrorLink: endpointUrl,
}
if resp != nil {
bbErr.ErrorCode = resp.StatusCode
bbErr.ErrorSummary = fmt.Sprint(resp.Body)
}
return bbErr
}

defer resp.Body.Close()
Expand Down

0 comments on commit 493afd4

Please sign in to comment.