Skip to content

Commit

Permalink
Don't use response to init Permit Errors after it's already consumed
Browse files Browse the repository at this point in the history
  • Loading branch information
roekatz committed Aug 21, 2024
1 parent ef1e865 commit c87fe7a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/enforcement/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (e *PermitEnforcer) parseResponse(res *http.Response) (*CheckResponse, erro

bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
permitError := errors.NewPermitUnexpectedError(err, res)
permitError := errors.NewPermitUnexpectedError(err, nil)
e.logger.Error("error reading Permit.Check() response from PDP", zap.Error(permitError))
return nil, permitError
}
Expand All @@ -74,13 +74,13 @@ func (e *PermitEnforcer) parseResponse(res *http.Response) (*CheckResponse, erro
}{&result}

if err := json.Unmarshal(bodyBytes, opaStruct); err != nil {
permitError := errors.NewPermitUnexpectedError(err, res)
permitError := errors.NewPermitUnexpectedError(err, nil)
e.logger.Error("error unmarshalling Permit.Check() response from OPA", zap.Error(permitError))
return nil, err
}
} else {
if err := json.Unmarshal(bodyBytes, &result); err != nil {
permitError := errors.NewPermitUnexpectedError(err, res)
permitError := errors.NewPermitUnexpectedError(err, nil)
e.logger.Error("error unmarshalling Permit.Check response from PDP", zap.Error(permitError))
return nil, permitError
}
Expand Down

0 comments on commit c87fe7a

Please sign in to comment.