diff options
author | 2023-06-02 15:19:43 +0200 | |
---|---|---|
committer | 2023-06-02 15:19:43 +0200 | |
commit | 2358cf4e433401e9a42336f056df1ab223f89057 (patch) | |
tree | d89d930f0ca983639eabf2e15285a4c4d03fa693 /internal/middleware/logger.go | |
parent | [performance] wrap httpclient response body to ensure drained before close (#... (diff) | |
download | gotosocial-2358cf4e433401e9a42336f056df1ab223f89057.tar.xz |
[bugfix] Overwrite API client closed errors with `499 - Client Closed Request` (#1857)
* [bugfix] Overwrite client closed errors with 499
* bleep bloop
* review changes
Diffstat (limited to 'internal/middleware/logger.go')
-rw-r--r-- | internal/middleware/logger.go | 17 |
1 files changed, 15 insertions, 2 deletions
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 |