-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherrors.go
68 lines (57 loc) · 1.17 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package pktconn
import (
"io"
"github.com/pkg/errors"
)
var (
ErrPayloadTooLarge = io.ErrShortWrite
ErrPayloadTooSmall = io.ErrUnexpectedEOF
errPayloadTooLarge = errors.Errorf("payload too large")
errChecksumError = errors.Errorf("checksum error")
)
type timeoutError interface {
Timeout() bool // Is it a timeout error
}
type temperaryError interface {
Temporary() bool
}
// IsTimeout checks if the error is a timeout error
func IsTimeout(err error) bool {
if err == nil {
return false
}
err = errors.Cause(err)
ne, ok := err.(timeoutError)
return ok && ne.Timeout()
}
// IsTimeout checks if the error is a timeout error
func IsTemporary(err error) bool {
if err == nil {
return false
}
err = errors.Cause(err)
ne, ok := err.(temperaryError)
return ok && ne.Temporary()
}
//// IsNetworkError check if the error is a connection error (close)
//func IsNetworkError(_err interface{}) bool {
// err, ok := _err.(error)
// if !ok {
// return false
// }
//
// err = errors.Cause(err)
// if err == io.EOF {
// return true
// }
//
// neterr, ok := err.(net.Error)
// if !ok {
// return false
// }
// if neterr.Timeout() {
// return false
// }
//
// return true
//}