Skip to content

Commit f9da808

Browse files
FelGelassaf758
authored andcommitted
Return NewErrorWithStatusCode instead of NewErrorWithStatusCodeAndResponse if response was not requested
1 parent 4a23268 commit f9da808

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

pkg/dataplane/http/context.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,18 +1122,18 @@ func (c *context) sendRequest(dataPlaneInput *v3io.DataPlaneInput,
11221122
if !success {
11231123
var re = regexp.MustCompile(".*X-V3io-Session-Key:.*")
11241124

1125+
sanitizedRequest := re.ReplaceAllString(request.String(), "X-V3io-Session-Key: SANITIZED")
1126+
_err := fmt.Errorf("Expected a 2xx response status code: %s\nRequest details:\n%s",
1127+
response.HTTPResponse.String(), sanitizedRequest)
1128+
11251129
// Include response in error only if caller has requested it
11261130
// Otherwise it will be released automatically
1127-
var _response *v3io.Response
11281131
if dataPlaneInput.IncludeResponseInError {
1129-
_response = response
1132+
err = v3ioerrors.NewErrorWithStatusCodeAndResponse(_err, statusCode, response)
1133+
} else {
1134+
err = v3ioerrors.NewErrorWithStatusCode(_err, statusCode)
11301135
}
1131-
sanitizedRequest := re.ReplaceAllString(request.String(), "X-V3io-Session-Key: SANITIZED")
1132-
err = v3ioerrors.NewErrorWithStatusCodeAndResponse(
1133-
fmt.Errorf("Expected a 2xx response status code: %s\nRequest details:\n%s",
1134-
response.HTTPResponse.String(), sanitizedRequest),
1135-
statusCode,
1136-
_response)
1136+
11371137
goto cleanup
11381138
}
11391139

pkg/dataplane/test/sync_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,6 @@ func (suite *syncKVTestSuite) TestIncludeResponseInError() {
10021002
suite.Assert().ElementsMatch(scatteredItemKeys, errorItemKeys)
10031003
}
10041004

1005-
10061005
func (suite *syncKVTestSuite) TestPutItemsWithError() {
10071006
items := map[string]map[string]interface{}{
10081007
"bob": {"age": 42, "feature": "mustache"},
@@ -1312,7 +1311,7 @@ func (suite *syncStreamTestSuite) TestStream() {
13121311
for _, cursorItem := range cursorItems {
13131312
shardName, err := cursorItem.GetFieldString("__name")
13141313
suite.Require().NoError(err, "Failed to get item name")
1315-
chunkMap , _, err := cursorItem.GetShard()
1314+
chunkMap, _, err := cursorItem.GetShard()
13161315
suite.Require().NoError(err, "Failed to get stream")
13171316

13181317
suite.Require().Contains(chunkMap, 0, "chunk indexes doesn't match")

0 commit comments

Comments
 (0)