forked from tarantool/go-tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
64 lines (55 loc) · 1.44 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
package tarantool
import (
"fmt"
"github.com/tarantool/go-iproto"
)
// Error is wrapper around error returned by Tarantool.
type Error struct {
Code iproto.Error
Msg string
ExtendedInfo *BoxError
}
// Error converts an Error to a string.
func (tnterr Error) Error() string {
if tnterr.ExtendedInfo != nil {
return tnterr.ExtendedInfo.Error()
}
return fmt.Sprintf("%s (0x%x)", tnterr.Msg, tnterr.Code)
}
// ClientError is connection error produced by this client,
// i.e. connection failures or timeouts.
type ClientError struct {
Code uint32
Msg string
}
// Error converts a ClientError to a string.
func (clierr ClientError) Error() string {
return fmt.Sprintf("%s (0x%x)", clierr.Msg, clierr.Code)
}
// Temporary returns true if next attempt to perform request may succeeded.
//
// Currently it returns true when:
//
// - Connection is not connected at the moment
//
// - request is timeouted
//
// - request is aborted due to rate limit
func (clierr ClientError) Temporary() bool {
switch clierr.Code {
case ErrConnectionNotReady, ErrTimeouted, ErrRateLimited, ErrIoError:
return true
default:
return false
}
}
// Tarantool client error codes.
const (
ErrConnectionNotReady = 0x4000 + iota
ErrConnectionClosed = 0x4000 + iota
ErrProtocolError = 0x4000 + iota
ErrTimeouted = 0x4000 + iota
ErrRateLimited = 0x4000 + iota
ErrConnectionShutdown = 0x4000 + iota
ErrIoError = 0x4000 + iota
)