func DevelopmentRecovery(p *prago.Request, recoveryData interface{}) { if p.App().DevelopmentMode { temp, err := template.New("development_error").Parse(developmentErrorTmpl) if err != nil { panic(err) } byteData := fmt.Sprintf("%s", recoveryData) buf := new(bytes.Buffer) err = temp.ExecuteTemplate(buf, "development_error", map[string]interface{}{ "name": byteData, "subname": "500 Internal Server Error", "stack": string(debug.Stack()), }) if err != nil { panic(err) } p.Response().Header().Add("Content-type", "text/html") p.Response().WriteHeader(500) p.Response().Write(buf.Bytes()) } else { p.Response().WriteHeader(500) p.Response().Write([]byte("We are sorry, some error occured. (500)")) } p.Log().Errorln(fmt.Sprintf("500 - error\n%s\nstack:\n", recoveryData)) p.Log().Errorln(string(debug.Stack())) }
func (s *Sessions) around(request prago.Request, next func()) { if request.IsProcessed() { next() return } sessionName := s.app.Data()["appName"].(string) session, err := s.cookieStore.Get(request.Request(), sessionName) if err != nil { request.Log().Errorln("Session not valid") request.Response().Header().Set("Set-Cookie", sessionName+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;") panic(err) } flashes := session.Flashes() if len(flashes) > 0 { request.SetData("flash_messages", flashes) prago.Must(session.Save(request.Request(), request.Response())) } request.SetData("session", session) next() }