Skip to content

Commit

Permalink
EOF error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prakash100198 committed Aug 29, 2023
1 parent 7d5fe5b commit c7473c2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/util/logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"bytes"
"github.com/devtron-labs/devtron/internal/middleware"
"github.com/devtron-labs/devtron/pkg/user"
"io"
Expand Down Expand Up @@ -42,16 +43,23 @@ func (impl LoggingMiddlewareImpl) LoggingMiddleware(next http.Handler) http.Hand
if err != nil {
log.Printf("AUDIT_LOG: user does not exists")
}
body, err := io.ReadAll(r.Body)

// Read the request body into a buffer
var bodyBuffer bytes.Buffer
_, err = io.Copy(&bodyBuffer, r.Body)
if err != nil {
log.Printf("AUDIT_LOG: error reading request body for urlPath: %s queryParams: %s userEmail: %s", r.URL.Path, r.URL.Query().Encode(), userEmail)
}

// Restore the request body for downstream handlers
r.Body = io.NopCloser(&bodyBuffer)

auditLogDto := &AuditLoggerDTO{
UrlPath: r.URL.Path,
UserEmail: userEmail,
UpdatedOn: time.Now(),
QueryParams: r.URL.Query().Encode(),
RequestPayload: body,
RequestPayload: bodyBuffer.Bytes(),
}
// Call the next handler in the chain.
next.ServeHTTP(d, r)
Expand Down

0 comments on commit c7473c2

Please sign in to comment.