http: don't log an error if the request is cancelled
Now that we have at least one endpoint that uses context for cancellation we can encounter this scenario where the returned error is a context.Cancelled or context.DeadlineExceeded. If the request.Context().Err() is not nil, then we know the request itself was cancelled, so we can log a different message at Info level, instad of the error.
This commit is contained in:
parent
df04f4fe52
commit
cfc829275c
|
@ -432,12 +432,20 @@ func (s *HTTPHandlers) wrap(handler endpoint, methods []string) http.HandlerFunc
|
|||
}
|
||||
|
||||
handleErr := func(err error) {
|
||||
httpLogger.Error("Request error",
|
||||
"method", req.Method,
|
||||
"url", logURL,
|
||||
"from", req.RemoteAddr,
|
||||
"error", err,
|
||||
)
|
||||
if req.Context().Err() != nil {
|
||||
httpLogger.Info("Request cancelled",
|
||||
"method", req.Method,
|
||||
"url", logURL,
|
||||
"from", req.RemoteAddr,
|
||||
"error", err)
|
||||
} else {
|
||||
httpLogger.Error("Request error",
|
||||
"method", req.Method,
|
||||
"url", logURL,
|
||||
"from", req.RemoteAddr,
|
||||
"error", err)
|
||||
}
|
||||
|
||||
switch {
|
||||
case isForbidden(err):
|
||||
resp.WriteHeader(http.StatusForbidden)
|
||||
|
|
Loading…
Reference in New Issue