Esempio n. 1
0
func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
	if err := recover(); err != nil {
		if err == USERSTOPRUN {
			return
		}
		if RunMode == "dev" {
			if !RecoverPanic {
				panic(err)
			} else {
				if ErrorsShow {
					if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok {
						executeError(handler, context)
						return
					}
				}
				var stack string
				Critical("the request url is ", context.Input.Url())
				Critical("Handler crashed with error", err)
				for i := 1; ; i++ {
					_, file, line, ok := runtime.Caller(i)
					if !ok {
						break
					}
					Critical(fmt.Sprintf("%s:%d", file, line))
					stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d", file, line))
				}
				showErr(err, context, stack)
			}
		} else {
			if !RecoverPanic {
				panic(err)
			} else {
				// in production model show all infomation
				if ErrorsShow {
					if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok {
						executeError(handler, context)
						return
					} else if handler, ok := ErrorMaps["503"]; ok {
						executeError(handler, context)
						return
					} else {
						context.WriteString(fmt.Sprint(err))
					}
				} else {
					Critical("the request url is ", context.Input.Url())
					Critical("Handler crashed with error", err)
					for i := 1; ; i++ {
						_, file, line, ok := runtime.Caller(i)
						if !ok {
							break
						}
						Critical(fmt.Sprintf("%s:%d", file, line))
					}
				}
			}
		}
	}
}
Esempio n. 2
0
// show error string as simple text message.
// if error string is empty, show 500 error as default.
func exception(errcode string, ctx *context.Context) {
	code, err := strconv.Atoi(errcode)
	if err != nil {
		code = 503
	}
	if h, ok := ErrorMaps[errcode]; ok {
		executeError(h, ctx, code)
		return
	} else if h, ok := ErrorMaps["503"]; ok {
		executeError(h, ctx, code)
		return
	} else {
		ctx.ResponseWriter.WriteHeader(code)
		ctx.WriteString(errcode)
	}
}
Esempio n. 3
0
func beegoFinishRouter2(ctx *context.Context) {
	ctx.WriteString("|FinishRouter2")
}
Esempio n. 4
0
func beegoAfterExec2(ctx *context.Context) {
	ctx.WriteString("|AfterExec2")
}
Esempio n. 5
0
func beegoBeforeExec2(ctx *context.Context) {
	ctx.WriteString("|BeforeExec2")
}
Esempio n. 6
0
func beegoBeforeRouter2(ctx *context.Context) {
	ctx.WriteString("|BeforeRouter2")
}
Esempio n. 7
0
func beegoFilterFunc(ctx *context.Context) {
	ctx.WriteString("hello")
}