-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log cancelled and failed requests #919
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
) | ||
|
||
type RoundTripStringer struct { | ||
Request *http.Request | ||
Response *http.Response | ||
Err error | ||
RequestBody []byte | ||
|
@@ -45,22 +46,21 @@ func (r RoundTripStringer) writeHeaders(sb *strings.Builder, prefix string, head | |
} | ||
|
||
func (r RoundTripStringer) String() string { | ||
request := r.Response.Request | ||
sb := strings.Builder{} | ||
sb.WriteString(fmt.Sprintf("%s %s", request.Method, | ||
escapeNewLines(request.URL.Path))) | ||
if request.URL.RawQuery != "" { | ||
sb.WriteString(fmt.Sprintf("%s %s", r.Request.Method, | ||
escapeNewLines(r.Request.URL.Path))) | ||
if r.Request.URL.RawQuery != "" { | ||
sb.WriteString("?") | ||
q, _ := url.QueryUnescape(request.URL.RawQuery) | ||
q, _ := url.QueryUnescape(r.Request.URL.RawQuery) | ||
sb.WriteString(q) | ||
} | ||
sb.WriteString("\n") | ||
if r.DebugHeaders { | ||
sb.WriteString("> * Host: ") | ||
sb.WriteString(escapeNewLines(request.Host)) | ||
sb.WriteString(escapeNewLines(r.Request.Host)) | ||
sb.WriteString("\n") | ||
if len(request.Header) > 0 { | ||
r.writeHeaders(&sb, "> ", request.Header) | ||
if len(r.Request.Header) > 0 { | ||
r.writeHeaders(&sb, "> ", r.Request.Header) | ||
sb.WriteString("\n") | ||
} | ||
} | ||
|
@@ -69,15 +69,17 @@ func (r RoundTripStringer) String() string { | |
sb.WriteString("\n") | ||
} | ||
sb.WriteString("< ") | ||
if r.Response != nil { | ||
sb.WriteString(fmt.Sprintf("%s %s", r.Response.Proto, r.Response.Status)) | ||
// Only display error on this line if the response body is empty. | ||
// Otherwise the response body will include details about the error. | ||
if len(r.ResponseBody) == 0 && r.Err != nil { | ||
sb.WriteString(fmt.Sprintf(" (Error: %s)", r.Err)) | ||
} | ||
} else { | ||
if r.Response == nil { | ||
sb.WriteString(fmt.Sprintf("Error: %s", r.Err)) | ||
return sb.String() | ||
} | ||
|
||
sb.WriteString(fmt.Sprintf("%s %s", r.Response.Proto, r.Response.Status)) | ||
// Only display error on this line if the response body is empty or the | ||
// client failed to read the response body. | ||
// Otherwise the response body will include details about the error. | ||
if len(r.ResponseBody) == 0 && r.Err != nil { | ||
sb.WriteString(fmt.Sprintf(" (Error: %s)", r.Err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a question, when length of response body is > 0 (line 86), is it always true that the Err would be nil? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily. We call the ErrorMapper function that parses the response into one of the SDK errors depending on the result. If the API responds with any of our standard error codes, This is just refactored from above, so there is no behavior change here. |
||
} | ||
if r.DebugHeaders && len(r.Response.Header) > 0 { | ||
sb.WriteString("\n") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could eliminate the first line to avoid duplication, perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep it since there are two distinct things being logged: the raw request/response pair, and then the decision to not retry the error. I've reordered them so that there is a logical flow in the log output.