-
Notifications
You must be signed in to change notification settings - Fork 495
/
error.go
47 lines (42 loc) · 1.4 KB
/
error.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
package api
// ServerErrorCode implements the ErrorCode
type ServerErrCode int
const (
ServerErrOK ServerErrCode = iota
ServerErrInvalidParam
ServerErrApplyResourceFailed
ServerErrRequestTaskInfoFailed
ServerErrUpdateHeartbeatFailed
ServerErrReleaseResourceFailed
ServerErrPreProcessFailed
ServerErrRedirectFailed
ServerErrEncodeJSONFailed
ServerErrGetServersFailed
ServerErrSendMessageFailed
ServerErrUnknownMessageType
)
var serverErrCode = map[ServerErrCode]string{
ServerErrOK: "request OK",
ServerErrInvalidParam: "invalid param",
ServerErrApplyResourceFailed: "apply resource failed",
ServerErrRequestTaskInfoFailed: "request task info failed",
ServerErrUpdateHeartbeatFailed: "update heartbeat failed",
ServerErrReleaseResourceFailed: "release resource failed",
ServerErrPreProcessFailed: "pre process failed",
ServerErrRedirectFailed: "redirect failed",
ServerErrEncodeJSONFailed: "encode json failed",
ServerErrGetServersFailed: "get servers failed",
ServerErrSendMessageFailed: "send message failed",
ServerErrUnknownMessageType: "unknown message type",
}
// String get error string from error code
func (sec ServerErrCode) String() string {
if _, ok := serverErrCode[sec]; !ok {
return "unknown server error"
}
return serverErrCode[sec]
}
// Int get code int from error code
func (sec ServerErrCode) Int() int {
return int(sec)
}