Skip to content

Commit

Permalink
Don't log error when verifying session and session not found
Browse files Browse the repository at this point in the history
Signed-off-by: Kate E. Reinecke <50168367+kreinecke@users.noreply.github.com>
  • Loading branch information
kreinecke committed Sep 20, 2019
1 parent f8a85a5 commit 3df620d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/jetstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/jetstream/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/jetstream/repository/interfaces/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down

0 comments on commit 3df620d

Please sign in to comment.