From 5616fce5b4c11bfafeed5a2ea6be2dae8143731e Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Tue, 28 Jan 2020 09:36:57 +0100 Subject: [PATCH] Use referer in error template --- handlers/handlers.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/handlers/handlers.go b/handlers/handlers.go index 3acbc1fa..fb45e738 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -495,14 +495,19 @@ func DefaultHomeHandler() http.Handler { } func (m *rootMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) { - err := m.fn(w, r) // Call handler function - if err == nil { + var errData struct { + Error error + Referer string + } + errData.Error = m.fn(w, r) // Call handler function + if errData.Error == nil { return } // This is where our error handling logic starts. if m.h.Config.LogLevel > config.LOG_LEVEL_OFF { - log.Printf("An error accured: %v", err) // Log the error. + log.Printf("An error accured: %v", errData.Error) // Log the error. } - respondWithError(m.h, w, r, err) + errData.Referer = r.Header.Get("Referer") + respondWithError(m.h, w, r, errData) }