From 2cf6e6e1d7df46df92135dd2bc19cdf2374d9157 Mon Sep 17 00:00:00 2001 From: Liam Burnand Date: Sun, 15 Oct 2023 14:39:02 +0100 Subject: [PATCH] Adding crash resistance --- views/helpers.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/views/helpers.go b/views/helpers.go index f9b47ff..924692d 100644 --- a/views/helpers.go +++ b/views/helpers.go @@ -50,7 +50,19 @@ func (v *Views) getSessionData(eC echo.Context) *Context { session, err := v.cookie.Get(eC.Request(), v.conf.SessionCookieName) if err != nil { log.Printf("error getting session: %+v", err) - return nil + err = session.Save(eC.Request(), eC.Response()) + if err != nil { + panic(fmt.Errorf("failed to save user session for getSessionData: %w", err)) + } + i := InternalContext{} + c := &Context{ + TitleText: i.TitleText, + Message: i.Message, + MsgType: i.MesType, + Callback: "/internal", + Version: v.conf.Version, + } + return c } var u, actual user.User