Replies: 1 comment 1 reply
-
|
You might want to create a logging middleware, something like this: func LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Create a response writer wrapper to capture the status code
rw := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
// Call the next handler, which includes gqlgen's handler
next.ServeHTTP(rw, r)
// After the handler, check if the response contains file upload size errors
if rw.statusCode == http.StatusOK {
// This is a simplistic check, you might need to look at the response body or specific headers
if strings.Contains(rw.responseBody, "file size exceeds") { // Adjust the string condition based on actual response content
log.Printf("File size exceeds limit: %v", rw.responseBody)
// Add telemetry or further logging here
}
}
})
}
type responseWriter struct {
http.ResponseWriter
statusCode int
responseBody string
}
func (rw *responseWriter) WriteHeader(statusCode int) {
rw.statusCode = statusCode
rw.ResponseWriter.WriteHeader(statusCode)
}
func (rw *responseWriter) Write(b []byte) (int, error) {
rw.responseBody = string(b) // You may want to capture only part of the response or use a different method
return rw.ResponseWriter.Write(b)
}This might work to you if you want to log. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a configuration like this:
which will reject large file sizes just fine. I want to hook into the rejection and log it and add telemetry. I can't seem to figure out how to hook into this rejection. I see it bail here: https://github.com/99designs/gqlgen/blob/master/graphql/handler/transport/http_form_multipart.go#L65
but that seems to short circuit all my handlers error presenters, around operations, etc. It sort of just bails and returns a simple response with a 200. Any ideas on how to log these failures?
Beta Was this translation helpful? Give feedback.
All reactions