etcd/error.go

50 lines
1.2 KiB
Go
Raw Normal View History

2013-07-12 21:42:07 +04:00
package main
import (
"encoding/json"
)
2013-07-13 00:35:43 +04:00
var errors map[int]string
func init() {
errors = make(map[int]string)
// command related errors
errors[100] = "Key Not Found"
errors[101] = "The given PrevValue is not equal to the value of the key"
2013-07-13 03:36:21 +04:00
errors[102] = "Not A File"
2013-08-01 04:26:45 +04:00
errors[103] = "Reached the max number of machines in the cluster"
2013-07-13 00:35:43 +04:00
// Post form related errors
errors[200] = "Value is Required in POST form"
errors[201] = "PrevValue is Required in POST form"
errors[202] = "The given TTL in POST form is not a number"
errors[203] = "The given index in POST form is not a number"
2013-07-13 00:35:43 +04:00
// raft related errors
errors[300] = "Raft Internal Error"
2013-07-15 02:30:16 +04:00
errors[301] = "During Leader Election"
2013-07-31 21:10:00 +04:00
// keyword
errors[400] = "The prefix of the given key is a keyword in etcd"
// etcd related errors
errors[500] = "watcher is cleared due to etcd recovery"
2013-07-13 00:35:43 +04:00
}
2013-07-12 21:42:07 +04:00
type jsonError struct {
2013-07-13 00:35:43 +04:00
ErrorCode int `json:"errorCode"`
Message string `json:"message"`
Cause string `json:"cause,omitempty"`
2013-07-12 21:42:07 +04:00
}
2013-07-13 00:35:43 +04:00
func newJsonError(errorCode int, cause string) []byte {
2013-07-12 21:42:07 +04:00
b, _ := json.Marshal(jsonError{
2013-07-13 00:35:43 +04:00
ErrorCode: errorCode,
Message: errors[errorCode],
Cause: cause,
2013-07-12 21:42:07 +04:00
})
return b
}