Skip to content

Commit

Permalink
remove traceId parsing from response
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed Dec 9, 2024
1 parent 2df5b51 commit 52ad604
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 25 deletions.
9 changes: 0 additions & 9 deletions pkg/infinity/http_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
type HTTPResponseError struct {
StatusCode int // HTTP status code
Message string // Extracted error message from the HTTP response if any
TraceID string // Extracted trace ID from the HTTP response if any
}

// Error implements the error interface for HTTPResponseError.
Expand All @@ -26,9 +25,6 @@ func (h *HTTPResponseError) Error() string {
if h.Message != "" {
err = errors.Join(err, fmt.Errorf("Error message from HTTP response: %s", h.Message))
}
if h.TraceID != "" {
err = errors.Join(err, fmt.Errorf("TraceID from HTTP response: %s", h.TraceID))
}
return err.Error()
}

Expand Down Expand Up @@ -65,11 +61,6 @@ func ParseErrorResponse(res *http.Response) error {
if unmarshalErr != nil {
return err
}
for _, key := range []string{"trace_id", "traceId", "traceID"} {
if traceId, ok := out[key].(string); ok && traceId != "" {
err.TraceID = traceId
}
}
for _, key := range []string{"error", "message", "status"} {
if errMsg, ok := out[key].(string); ok && errMsg != "" {
err.Message = errMsg
Expand Down
16 changes: 0 additions & 16 deletions pkg/infinity/http_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,6 @@ func TestParseErrorResponse(t *testing.T) {
},
wantErr: "unsuccessful HTTP response\nHTTP status code: 500 Internal Server Error\nError message from HTTP response: foo",
},
{
name: "Internal server error with JSON traceId",
res: &http.Response{
StatusCode: http.StatusInternalServerError,
Body: io.NopCloser(strings.NewReader(`{ "traceId" : "bar" }`)),
},
wantErr: "unsuccessful HTTP response\nHTTP status code: 500 Internal Server Error\nTraceID from HTTP response: bar",
},
{
name: "Internal server error with JSON message and traceId",
res: &http.Response{
StatusCode: http.StatusInternalServerError,
Body: io.NopCloser(strings.NewReader(`{ "error" : "foo", "traceId" : "bar" }`)),
},
wantErr: "unsuccessful HTTP response\nHTTP status code: 500 Internal Server Error\nError message from HTTP response: foo\nTraceID from HTTP response: bar",
},
{
name: "Invalid JSON content response",
res: &http.Response{
Expand Down

0 comments on commit 52ad604

Please sign in to comment.