sing/common/exceptions/timeout.go
2024-09-10 23:46:03 +08:00

23 lines
410 B
Go

package exceptions
import (
"errors"
"net"
)
type TimeoutError interface {
Timeout() bool
}
func IsTimeout(err error) bool {
var netErr net.Error
if errors.As(err, &netErr) {
//goland:noinspection GoDeprecation
//nolint:staticcheck
return netErr.Temporary() && netErr.Timeout()
}
if timeoutErr, isTimeout := Cast[TimeoutError](err); isTimeout {
return timeoutErr.Timeout()
}
return false
}