From 3df620d5fc39bbfbffed6959bf364e07a63a1b55 Mon Sep 17 00:00:00 2001 From: "Kate E. Reinecke" <50168367+kreinecke@users.noreply.github.com> Date: Fri, 20 Sep 2019 14:07:42 +0100 Subject: [PATCH] Don't log error when verifying session and session not found Signed-off-by: Kate E. Reinecke <50168367+kreinecke@users.noreply.github.com> --- src/jetstream/main.go | 5 ++++- src/jetstream/middleware.go | 1 - src/jetstream/repository/interfaces/errors.go | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/jetstream/main.go b/src/jetstream/main.go index 5820dc31ae..de91d77f43 100644 --- a/src/jetstream/main.go +++ b/src/jetstream/main.go @@ -934,6 +934,7 @@ func getUICustomHTTPErrorHandler(staticDir string, defaultHandler echo.HTTPError // EchoV2DefaultHTTPErrorHandler ensures we get V2 error behaviour // i.e. no wrapping in 'message' JSON object func echoV2DefaultHTTPErrorHandler(err error, c echo.Context) { + code := http.StatusInternalServerError msg := http.StatusText(code) if he, ok := err.(*echo.HTTPError); ok { @@ -957,7 +958,9 @@ func echoV2DefaultHTTPErrorHandler(err error, c echo.Context) { } } - if err != nil { + //Only log if there is a message to log + he, _ := err.(*echo.HTTPError) + if err != nil && he.Message.(string) != "" { c.Logger().Error(err) } } diff --git a/src/jetstream/middleware.go b/src/jetstream/middleware.go index a019c8ccd3..7fcc25a207 100644 --- a/src/jetstream/middleware.go +++ b/src/jetstream/middleware.go @@ -73,7 +73,6 @@ func (p *portalProxy) sessionMiddleware(h echo.HandlerFunc) echo.HandlerFunc { // Don't log an error if we are verifying the session, as a failure is not an error isVerify := strings.HasSuffix(c.Request().RequestURI, "/auth/session/verify") - log.Error(c.Request().RequestURI) if isVerify { // Tell the frontend what the Cookie Domain is so it can check if sessions will work c.Response().Header().Set(StratosDomainHeader, p.Config.CookieDomain) diff --git a/src/jetstream/repository/interfaces/errors.go b/src/jetstream/repository/interfaces/errors.go index c47939883f..610e7caeca 100644 --- a/src/jetstream/repository/interfaces/errors.go +++ b/src/jetstream/repository/interfaces/errors.go @@ -25,13 +25,18 @@ func (e ErrHTTPShadow) Error() string { } func NewHTTPError(status int, userFacingError string) error { - return NewHTTPShadowError(status, userFacingError, "") + return NewHTTPShadowError(status, userFacingError, "", true) } func NewHTTPShadowError(status int, userFacingError string, fmtString string, args ...interface{}) error { + //Only set the HTTPError field of the ErrHTTPShadow struct if we have been passed an error message intended for logging + httpErrorMsg := "" + if len(fmtString) > 0 { + httpErrorMsg = fmt.Sprintf(`{"error":%q}`, userFacingError) + } shadowError := ErrHTTPShadow{ UserFacingError: userFacingError, - HTTPError: echo.NewHTTPError(status, fmt.Sprintf(`{"error":%q}`, userFacingError)), + HTTPError: echo.NewHTTPError(status, httpErrorMsg), } if len(fmtString) > 0 { shadowError.LogMessage = fmt.Sprintf(fmtString, args...)