From 2358cf4e433401e9a42336f056df1ab223f89057 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 2 Jun 2023 15:19:43 +0200 Subject: [bugfix] Overwrite API client closed errors with `499 - Client Closed Request` (#1857) * [bugfix] Overwrite client closed errors with 499 * bleep bloop * review changes --- internal/middleware/logger.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'internal/middleware/logger.go') diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go index 8acb742fb..58f90b088 100644 --- a/internal/middleware/logger.go +++ b/internal/middleware/logger.go @@ -27,6 +27,7 @@ import ( "codeberg.org/gruf/go-kv" "codeberg.org/gruf/go-logger/v2/level" "github.com/gin-gonic/gin" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/log" ) @@ -91,11 +92,23 @@ func Logger(logClientIP bool) gin.HandlerFunc { l = l.WithField("error", c.Errors) } + // Get appropriate text for this code. + statusText := http.StatusText(code) + if statusText == "" { + // Look for custom codes. + switch code { + case gtserror.StatusClientClosedRequest: + statusText = gtserror.StatusTextClientClosedRequest + default: + statusText = "Unknown Status" + } + } + // Generate a nicer looking bytecount size := bytesize.Size(c.Writer.Size()) - // Finally, write log entry with status text body size - l.Logf(lvl, "%s: wrote %s", http.StatusText(code), size) + // Finally, write log entry with status text + body size. + l.Logf(lvl, "%s: wrote %s", statusText, size) }() // Process request -- cgit v1.2.3