Skip to content

Commit 590c927

Browse files
authored
Merge pull request #96 from deploymenttheory/dev
Dev
2 parents 8358863 + 00f201e commit 590c927

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

httpclient/httpclient_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (c *Client) executeRequest(method, endpoint string, body, out interface{})
318318
return nil, c.handleErrorResponse(resp, out, log, method, endpoint)
319319
}
320320

321-
// executeHTTPRequest sends an HTTP request using the client's HTTP client. It logs the request and error details, if any,
321+
// do sends an HTTP request using the client's HTTP client. It logs the request and error details, if any,
322322
// using structured logging with zap fields.
323323
//
324324
// Parameters:

logger/zaplogger_logfields.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ func (d *defaultLogger) LogRequestEnd(method string, url string, statusCode int,
3838
// LogError logs an error that occurs during the processing of an HTTP request if the current log level permits.
3939
func (d *defaultLogger) LogError(method string, url string, statusCode int, err error, stacktrace string) {
4040
if d.logLevel <= LogLevelError {
41+
errorMessage := ""
42+
if err != nil {
43+
errorMessage = err.Error()
44+
}
45+
4146
fields := []zap.Field{
4247
zap.String("event", "request_error"),
4348
zap.String("method", method),
4449
zap.String("url", url),
4550
zap.Int("status_code", statusCode),
46-
zap.String("error_message", err.Error()),
51+
zap.String("error_message", errorMessage),
4752
zap.String("stacktrace", stacktrace),
4853
}
4954
d.logger.Error("Error during HTTP request", fields...)

0 commit comments

Comments
 (0)