diff --git a/api/handler/util.go b/api/handler/util.go index b14fb64bb..d43818b01 100644 --- a/api/handler/util.go +++ b/api/handler/util.go @@ -16,15 +16,17 @@ import ( ) func (h *handler) logAndSendError(w http.ResponseWriter, logText string, reqInfo *api.ReqInfo, err error, additional ...zap.Field) { - fields := []zap.Field{zap.String("request_id", reqInfo.RequestID), + code := api.WriteErrorResponse(w, reqInfo, transformToS3Error(err)) + fields := []zap.Field{ + zap.Int("status", code), + zap.String("request_id", reqInfo.RequestID), zap.String("method", reqInfo.API), - zap.String("bucket_name", reqInfo.BucketName), - zap.String("object_name", reqInfo.ObjectName), + zap.String("bucket", reqInfo.BucketName), + zap.String("object", reqInfo.ObjectName), + zap.String("description", logText), zap.Error(err)} fields = append(fields, additional...) - - h.log.Error(logText, fields...) - api.WriteErrorResponse(w, reqInfo, transformToS3Error(err)) + h.log.Error("call method", fields...) } func transformToS3Error(err error) error { diff --git a/api/response.go b/api/response.go index 8b8e9c224..6c3415e14 100644 --- a/api/response.go +++ b/api/response.go @@ -110,7 +110,7 @@ var s3ErrorResponseMap = map[string]string{ } // WriteErrorResponse writes error headers. -func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) { +func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) int { code := http.StatusInternalServerError if e, ok := err.(errors.Error); ok { @@ -130,6 +130,7 @@ func WriteErrorResponse(w http.ResponseWriter, reqInfo *ReqInfo, err error) { errorResponse := getAPIErrorResponse(reqInfo, err) encodedErrorResponse := EncodeResponse(errorResponse) WriteResponse(w, code, encodedErrorResponse, MimeXML) + return code } // If none of the http routes match respond with appropriate errors. diff --git a/api/router.go b/api/router.go index 889a210a4..a8e3acd1b 100644 --- a/api/router.go +++ b/api/router.go @@ -154,16 +154,8 @@ func logErrorResponse(l *zap.Logger) mux.MiddlewareFunc { // pass execution: h.ServeHTTP(lw, r) - // Ignore <300 status codes - if lw.statusCode >= http.StatusMultipleChoices { - l.Error("something went wrong", - zap.Int("status", lw.statusCode), - zap.String("request_id", GetRequestID(r.Context())), - zap.String("method", mux.CurrentRoute(r).GetName()), - zap.String("bucket", reqInfo.BucketName), - zap.String("object", reqInfo.ObjectName), - zap.String("description", http.StatusText(lw.statusCode))) - + // Ignore >400 status codes + if lw.statusCode >= http.StatusBadRequest { return }