Skip to content

Commit 8711ceb

Browse files
FelGelassaf758
authored andcommitted
Revert "Include response in err struct"
This reverts commit 1aeefa4.
1 parent 1e1b186 commit 8711ceb

File tree

2 files changed

+4
-73
lines changed

2 files changed

+4
-73
lines changed

pkg/dataplane/http/context.go

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,7 @@ func (c *context) GetItemsSync(getItemsInput *v3io.GetItemsInput) (*v3io.Respons
341341
false)
342342

343343
if err != nil {
344-
errorWithStatusAndResponse, ok := err.(v3ioerrors.ErrorWithStatusCodeAndResponse)
345-
if !ok {
346-
return nil, err
347-
}
348-
if errorWithStatusAndResponse.Response() == nil || errorWithStatusAndResponse.Response().HTTPResponse == nil {
349-
return nil, err
350-
}
351-
352-
// if error has included response - attempt to parse it
353-
// unlike regular response, there is no need to release response from `errorWithStatusAndResponse`
354-
response = errorWithStatusAndResponse.Response()
355-
response.Output, _ = c.getItemsParseJSONResponse(response, getItemsInput)
356-
return response, err
344+
return nil, err
357345
}
358346

359347
contentType := string(response.HeaderPeek("Content-Type"))
@@ -1016,20 +1004,7 @@ func (c *context) sendRequestAndXMLUnmarshal(dataPlaneInput *v3io.DataPlaneInput
10161004

10171005
response, err := c.sendRequest(dataPlaneInput, method, path, query, headers, body, false)
10181006
if err != nil {
1019-
errorWithStatusAndResponse, ok := err.(v3ioerrors.ErrorWithStatusCodeAndResponse)
1020-
if !ok {
1021-
return nil, err
1022-
}
1023-
if errorWithStatusAndResponse.Response() == nil || errorWithStatusAndResponse.Response().HTTPResponse == nil {
1024-
return nil, err
1025-
}
1026-
1027-
// if error has included response - attempt to parse it
1028-
// unlike regular response, there is no need to release response from `errorWithStatusAndResponse`
1029-
response = errorWithStatusAndResponse.Response()
1030-
_ = xml.Unmarshal(response.Body(), output)
1031-
response.Output = output
1032-
return response, err
1007+
return nil, err
10331008
}
10341009

10351010
// unmarshal the body into the output
@@ -1141,18 +1116,11 @@ func (c *context) sendRequest(dataPlaneInput *v3io.DataPlaneInput,
11411116
// make sure we got expected status
11421117
if !success {
11431118
var re = regexp.MustCompile(".*X-V3io-Session-Key:.*")
1144-
1145-
// Include response in error only if caller has requested it
1146-
var _response *v3io.Response
1147-
if !releaseResponse {
1148-
_response = response
1149-
}
11501119
sanitizedRequest := re.ReplaceAllString(request.String(), "X-V3io-Session-Key: SANITIZED")
1151-
err = v3ioerrors.NewErrorWithStatusCodeAndResponse(
1120+
err = v3ioerrors.NewErrorWithStatusCode(
11521121
fmt.Errorf("Expected a 2xx response status code: %s\nRequest details:\n%s",
11531122
response.HTTPResponse.String(), sanitizedRequest),
1154-
statusCode,
1155-
_response)
1123+
statusCode)
11561124
goto cleanup
11571125
}
11581126

pkg/errors/errors.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package v3ioerrors
22

33
import (
44
"errors"
5-
6-
v3io "github.com/v3io/v3io-go/pkg/dataplane"
7-
"github.com/valyala/fasthttp"
85
)
96

107
var ErrInvalidTypeConversion = errors.New("Invalid type conversion")
@@ -17,11 +14,6 @@ type ErrorWithStatusCode struct {
1714
statusCode int
1815
}
1916

20-
type ErrorWithStatusCodeAndResponse struct {
21-
ErrorWithStatusCode
22-
response *v3io.Response
23-
}
24-
2517
func NewErrorWithStatusCode(err error, statusCode int) ErrorWithStatusCode {
2618
return ErrorWithStatusCode{
2719
error: err,
@@ -36,32 +28,3 @@ func (e ErrorWithStatusCode) StatusCode() int {
3628
func (e ErrorWithStatusCode) Error() string {
3729
return e.error.Error()
3830
}
39-
40-
func NewErrorWithStatusCodeAndResponse(err error,
41-
statusCode int,
42-
response *v3io.Response) ErrorWithStatusCodeAndResponse {
43-
44-
// Copy response struct since original response will be released if error is encountered
45-
var _copiedResponse *v3io.Response
46-
if response != nil {
47-
copiedHTTPResponse := &fasthttp.Response{}
48-
if response.HTTPResponse != nil {
49-
response.HTTPResponse.CopyTo(copiedHTTPResponse)
50-
}
51-
_copiedResponse = &v3io.Response{
52-
Output: response.Output,
53-
Context: response.Context,
54-
Error: response.Error,
55-
HTTPResponse: copiedHTTPResponse,
56-
}
57-
}
58-
59-
return ErrorWithStatusCodeAndResponse{
60-
ErrorWithStatusCode: NewErrorWithStatusCode(err, statusCode),
61-
response: _copiedResponse,
62-
}
63-
}
64-
65-
func (e ErrorWithStatusCodeAndResponse) Response() *v3io.Response {
66-
return e.response
67-
}

0 commit comments

Comments
 (0)