@@ -32,7 +32,7 @@ func GinRecoveryHandler(c *gin.Context) {
3232 }
3333 }
3434 }
35- fileLine , stack := stack (5 )
35+ fileLine , stack := stack (3 )
3636 httpRequest , _ := httputil .DumpRequest (c .Request , false )
3737 headers := strings .Split (string (httpRequest ), "\r \n " )
3838 for idx , header := range headers {
@@ -42,14 +42,23 @@ func GinRecoveryHandler(c *gin.Context) {
4242 }
4343 }
4444 headersToStr := strings .Join (headers , "\r \n " )
45- if brokenPipe {
46- notify .ErrorThrottle ("ginPanicRecovery:" + fileLine , time .Minute , "Panic Detected" , fmt .Sprintf ("%s\n %s" , err , headersToStr ))
47- } else if gin .IsDebugging () {
48- notify .ErrorThrottle ("ginPanicRecovery:" + fileLine , time .Minute , "Panic Detected" , fmt .Sprintf ("[Recovery] panic recovered:\n %s\n %s\n %s" ,
49- headersToStr , err , stack ))
50- } else {
51- notify .ErrorThrottle ("ginPanicRecovery:" + fileLine , time .Minute , "Panic Detected" , fmt .Sprintf ("[Recovery] panic recovered:\n %s\n %s" ,
52- err , stack ))
45+ switch {
46+ case brokenPipe :
47+ notify .ErrorThrottle ("ginPanicRecovery:" + fileLine ,
48+ time .Minute , "Panic Detected" ,
49+ fmt .Sprintf ("%s\n %s" , err , headersToStr ))
50+ case gin .IsDebugging ():
51+ notify .ErrorThrottle ("ginPanicRecovery:" + fileLine ,
52+ time .Minute , "Panic Detected" ,
53+ fmt .Sprintf ("[Recovery] panic recovered:\n %s\n %s\n %s" ,
54+ headersToStr , err , stack ),
55+ )
56+ default :
57+ notify .ErrorThrottle ("ginPanicRecovery:" + fileLine ,
58+ time .Minute , "Panic Detected" ,
59+ fmt .Sprintf ("[Recovery] panic recovered:\n %s\n %s" ,
60+ err , stack ),
61+ )
5362 }
5463 if brokenPipe {
5564 // If the connection is dead, we can't write a status to it.
0 commit comments