Skip to content
Snippets Groups Projects
Commit fcaee22e authored by Travis Ralston's avatar Travis Ralston
Browse files

Log a redacted URL during request panics

parent 911a5ffb
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/turt2live/matrix-media-repo/api/_responses" "github.com/turt2live/matrix-media-repo/api/_responses"
"github.com/turt2live/matrix-media-repo/api/_routers" "github.com/turt2live/matrix-media-repo/api/_routers"
"github.com/turt2live/matrix-media-repo/util"
) )
func buildPrimaryRouter() *httprouter.Router { func buildPrimaryRouter() *httprouter.Router {
...@@ -54,7 +55,7 @@ func finishCorsFn(w http.ResponseWriter, r *http.Request) { ...@@ -54,7 +55,7 @@ func finishCorsFn(w http.ResponseWriter, r *http.Request) {
} }
func panicFn(w http.ResponseWriter, r *http.Request, i interface{}) { func panicFn(w http.ResponseWriter, r *http.Request, i interface{}) {
logrus.Errorf("Panic received on %s %s: %s", r.Method, r.URL.String(), i) logrus.Errorf("Panic received on %s %s: %s", r.Method, util.GetLogSafeUrl(r), i)
if e, ok := i.(error); ok { if e, ok := i.(error); ok {
sentry.CaptureException(e) sentry.CaptureException(e)
......
...@@ -2,6 +2,7 @@ package util ...@@ -2,6 +2,7 @@ package util
import ( import (
"net/http" "net/http"
"net/url"
"strings" "strings"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -37,3 +38,9 @@ func GetLogSafeQueryString(r *http.Request) string { ...@@ -37,3 +38,9 @@ func GetLogSafeQueryString(r *http.Request) string {
return qs.Encode() return qs.Encode()
} }
func GetLogSafeUrl(r *http.Request) string {
copyUrl, _ := url.ParseRequestURI(r.URL.String())
copyUrl.RawQuery = GetLogSafeQueryString(r)
return copyUrl.String()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment