Skip to content

Commit

Permalink
chore: using error from router http client (#2628)
Browse files Browse the repository at this point in the history
  • Loading branch information
chandumlg authored Nov 1, 2022
1 parent 79e3e34 commit a6e253b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
13 changes: 2 additions & 11 deletions router/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (network *NetHandleT) SendPost(ctx context.Context, structData integrations
if err != nil {
return &utils.SendPostResponse{
StatusCode: http.StatusGatewayTimeout,
ResponseBody: []byte(fmt.Sprintf(`504 Unable to make "%s" request for URL : "%s"`, requestMethod, postInfo.URL)),
ResponseBody: []byte(fmt.Sprintf(`504 Unable to make "%s" request for URL : "%s". Error: %s`, requestMethod, postInfo.URL, err.Error())),
}
}

Expand All @@ -174,7 +174,7 @@ func (network *NetHandleT) SendPost(ctx context.Context, structData integrations
if err != nil {
return &utils.SendPostResponse{
StatusCode: resp.StatusCode,
ResponseBody: []byte(fmt.Sprintf(`Failed to read response body for request for URL : "%s"`, postInfo.URL)),
ResponseBody: []byte(fmt.Sprintf(`Failed to read response body for request for URL : "%s". Error: %s`, postInfo.URL, err.Error())),
}
}
network.logger.Debug(postInfo.URL, " : ", req.Proto, " : ", resp.Proto, resp.ProtoMajor, resp.ProtoMinor, resp.ProtoAtLeast)
Expand All @@ -196,15 +196,6 @@ func (network *NetHandleT) SendPost(ctx context.Context, structData integrations
respBody = []byte("redacted due to unsupported content-type")
}

if err != nil {
network.logger.Error("Errored when sending request to the server", err)
return &utils.SendPostResponse{
StatusCode: http.StatusGatewayTimeout,
ResponseBody: respBody,
ResponseContentType: contentTypeHeader,
}
}

return &utils.SendPostResponse{
StatusCode: resp.StatusCode,
ResponseBody: respBody,
Expand Down
4 changes: 3 additions & 1 deletion router/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package router
import (
"bytes"
"context"
"fmt"
"io"
"net/http"

Expand Down Expand Up @@ -113,7 +114,8 @@ var _ = Describe("Network", func() {

resp := network.SendPost(ctx, structData)
Expect(resp.StatusCode).To(Equal(http.StatusGatewayTimeout))
Expect(string(resp.ResponseBody)).To(Equal("504 Unable to make \"\" request for URL : \"https://www.google-analytics.com/collect\""))
fmt.Println(string(resp.ResponseBody))
Expect(string(resp.ResponseBody)).To(Equal("504 Unable to make \"\" request for URL : \"https://www.google-analytics.com/collect\". Error: Get \"https://www.google-analytics.com/collect\": context canceled"))
})
})

Expand Down

0 comments on commit a6e253b

Please sign in to comment.