-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRpcErrorCode.go
More file actions
63 lines (54 loc) · 1.59 KB
/
RpcErrorCode.go
File metadata and controls
63 lines (54 loc) · 1.59 KB
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
package jrm1
import "errors"
// RPC error codes.
const (
RpcErrorCode_RequestIsNotReadable = -1
RpcErrorCode_InvalidRequest = -2
RpcErrorCode_UnsupportedProtocol = -4
RpcErrorCode_UnknownMethod = -8
RpcErrorCode_InvalidParameters = -16
RpcErrorCode_InternalRpcError = -32
//
RpcErrorCode_ReservedForFuture_1 = -64
RpcErrorCode_ReservedForFuture_2 = -128
RpcErrorCode_ReservedForFuture_3 = -256
// User generated error codes.
RpcErrorCode_UGEC_Minimal = 1
)
const (
ErrUnsupportedErrorCode = "unsupported error code"
ErrFUnknownErrorCode = "unknown error code: %v"
)
// RpcErrorCode is a code of an RPC error.
type RpcErrorCode int
// Check ensures that error code is a valid error code generated by an RPC
// server. This check refuses error codes having special values for
// user-generated errors.
func (rec RpcErrorCode) Check() (err error) {
switch rec {
case RpcErrorCode_RequestIsNotReadable,
RpcErrorCode_InvalidRequest,
RpcErrorCode_UnsupportedProtocol,
RpcErrorCode_UnknownMethod,
RpcErrorCode_InvalidParameters,
RpcErrorCode_InternalRpcError,
RpcErrorCode_ReservedForFuture_1,
RpcErrorCode_ReservedForFuture_2,
RpcErrorCode_ReservedForFuture_3:
return nil
default:
return errors.New(ErrUnsupportedErrorCode)
}
}
// IsGeneratedByUser checks whether the error code is a special value used by
// user-generated errors.
func (rec RpcErrorCode) IsGeneratedByUser() bool {
if rec >= RpcErrorCode_UGEC_Minimal {
return true
}
return false
}
// Int returns RPC error code as an integer number.
func (rec RpcErrorCode) Int() int {
return int(rec)
}