zap
zap copied to clipboard
For broken pipe, determine whether it can be encapsulated in the gin framework?
https://github.com/gin-contrib/zap/blob/062a8ac606569fff538abb3a325b4d387aeb4a69/zap.go#L72 I have also seen such code snippets in the gin framework. Here you have done this again. Is it possible to encapsulate an IsBroken func instead of writing this every time.
Just like below:
// IsBroken check for a broken connection, as it is not really a
// condition that warrants a panic stack trace.
func IsBroken(err interface{}) bool {
if ne, ok := err.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok {
errMsg := strings.ToLower(se.Error())
debugPrintf("os syscall error:%s", errMsg)
if strings.Contains(errMsg, "broken pipe") ||
strings.Contains(errMsg, "reset by peer"){
return true
}
}
}
return false
}