浏览代码

Made errorFrame an interface that can implemented by the different types of errors from a cassandra server.

Nimi Wariboko Jr 11 年之前
父节点
当前提交
0879b50f64
共有 1 个文件被更改,包括 76 次插入0 次删除
  1. 76 0
      errors.go

+ 76 - 0
errors.go

@@ -0,0 +1,76 @@
+package gocql
+
+const (
+	errServer        = 0x0000
+	errProtocol      = 0x000A
+	errCredentials   = 0x0100
+	errUnavailable   = 0x1000
+	errOverloaded    = 0x1001
+	errBootstrapping = 0x1002
+	errTruncate      = 0x1003
+	errWriteTimeout  = 0x1100
+	errReadTimeout   = 0x1200
+	errSyntax        = 0x2000
+	errUnauthorized  = 0x2100
+	errInvalid       = 0x2200
+	errConfig        = 0x2300
+	errAlreadyExists = 0x2400
+	errUnprepared    = 0x2500
+)
+
+type errorFrame interface {
+	Code() int
+	Message() string
+	Error() string
+}
+
+type errorResponse struct {
+	code    int
+	message string
+}
+
+func (e errorResponse) Code() int {
+	return e.code
+}
+
+func (e errorResponse) Message() string {
+	return e.message
+}
+
+func (e errorResponse) Error() string {
+	return e.Message()
+}
+
+type errRespUnavailable struct {
+	errorResponse
+	Consistency Consistency
+	Required    int
+	Alive       int
+}
+
+type errRespWriteTimeout struct {
+	errorResponse
+	Consistency Consistency
+	Received    int
+	BlockFor    int
+	WriteType   string
+}
+
+type errRespReadTimeout struct {
+	errorResponse
+	Consistency Consistency
+	Received    int
+	BlockFor    int
+	DataPresent byte
+}
+
+type errRespAlreadyExists struct {
+	errorResponse
+	Keyspace string
+	Table    string
+}
+
+type errRespUnprepared struct {
+	errorResponse
+	StatementId []byte
+}