From 10dc322af595ecc8b85d58b514e82e97a9f4ea5e Mon Sep 17 00:00:00 2001 From: Masahiro Nagano Date: Wed, 8 Apr 2020 11:28:56 +0900 Subject: [PATCH] only change zap context when error --- proxy/handler.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/proxy/handler.go b/proxy/handler.go index 05d1e44..0c3aadd 100644 --- a/proxy/handler.go +++ b/proxy/handler.go @@ -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)