0

How to override Beego's recoverPanic? I have set the flag recoverpanic = false and write my own recover but have no luck, it just print the panic message to the console instead jumping to my recover function.

func main() {
    defer recoverPanic()
    beego.Run()
}

func recoverPanic() {
    if err := recover(); err != nil {
        fmt.Println("Panic should go there")
    }
}

I want to catch all unexpect errors, e.g nil pointer, write some log and send email to our maintainers.

windyzboy
  • 1,358
  • 16
  • 20

1 Answers1

0

You should add recoverPanic at the beginning of every goroutine. You add the recover in the main function and it won't cache the panic of request.

Try this in Beego:

func (c *MainController) Get() {
    defer recoverPanic()

    ... Your Code ...
}
Bryce
  • 3,046
  • 2
  • 19
  • 25