Skip to content

Commit

Permalink
add more debug at error case
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustafa Kuscu committed Oct 26, 2020
1 parent bc6db64 commit 4c6fb87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (h *HttpClient) Delete(rawurl string, in, out interface{}) error {
func (h *HttpClient) do(rawurl, method string, in, out interface{}) error {
resp, err := h.open(rawurl, method, in, out)
if err != nil {
if resp != nil {
fmt.Printf("Response error status %s from %s at %s, error: %+v\n", resp.Status, resp.Request.URL, time.Now().Format(time.RFC3339), err)
} else {
fmt.Printf("Response error at %s, error: %+v\n", time.Now().Format(time.RFC3339), err)
}
return &HttpError{Status: 503}
}
defer resp.Body.Close()
Expand Down
10 changes: 10 additions & 0 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func Test_debug_http_postman(t *testing.T) {
require.NoError(t, err)
}

func Test_debug_unreachable_host(t *testing.T) {
client := NewHttpClient("https://postman-echo.com/post", WithDebug())
in := &PostIn{
DummyField: "a123456",
}
out := &PostIn{}
err := client.Post("http://192.168.1.189", in, out)
require.Error(t, err)
}

func Test_debug_http_postman_without_debug(t *testing.T) {
client := NewHttpClient("https://postman-echo.com/post")
in := &PostIn{
Expand Down

0 comments on commit 4c6fb87

Please # to comment.