Skip to content

Commit

Permalink
Merge pull request #39 from kazeburo/change-zap-context-when-error
Browse files Browse the repository at this point in the history
only change zap context when error
  • Loading branch information
kazeburo committed Apr 8, 2020
2 parents deb96a4 + 10dc322 commit 5128f77
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,16 @@ func (proxy *Proxy) ServeHTTP(writer http.ResponseWriter, originalRequest *http.
return
}

logger := proxy.logger.With(
zap.String("request_host", originalRequest.Host),
zap.String("request_path", originalRequest.URL.Path),
zap.String("proxy_host", proxyRequest.URL.Host),
zap.String("proxy_scheme", proxyRequest.URL.Scheme),
zap.String("proxy_id", proxyID),
)

// Convert a request into a response by using its Transport.
response, err := proxy.Transport.RoundTrip(proxyRequest)
if err != nil {
logger := proxy.logger.With(
zap.String("request_host", originalRequest.Host),
zap.String("request_path", originalRequest.URL.Path),
zap.String("proxy_host", proxyRequest.URL.Host),
zap.String("proxy_scheme", proxyRequest.URL.Scheme),
zap.String("proxy_id", proxyID),
)
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
logger.Error("ErrorFromProxy", zap.Error(err))
writer.WriteHeader(http.StatusGatewayTimeout)
Expand Down

0 comments on commit 5128f77

Please sign in to comment.