2013-08-29 16:51:23 +08:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
2013-08-30 12:36:57 +08:00
|
|
|
"fmt"
|
2013-08-29 16:51:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrWorkWarning = errors.New("Work warning")
|
2013-12-26 15:28:42 +08:00
|
|
|
ErrInvalidData = errors.New("Invalid data")
|
2013-08-29 16:51:23 +08:00
|
|
|
ErrWorkFail = errors.New("Work fail")
|
|
|
|
ErrWorkException = errors.New("Work exeption")
|
|
|
|
ErrDataType = errors.New("Invalid data type")
|
2013-12-26 15:28:42 +08:00
|
|
|
ErrLostConn = errors.New("Lost connection with Gearmand")
|
2013-08-29 16:51:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Extract the error message
|
2013-12-26 15:28:42 +08:00
|
|
|
func getError(data []byte) (err error) {
|
2013-08-29 16:51:23 +08:00
|
|
|
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
|
|
|
|
if len(rel) != 2 {
|
|
|
|
err = fmt.Errorf("Not a error data: %V", data)
|
|
|
|
return
|
|
|
|
}
|
2013-08-30 11:20:51 +08:00
|
|
|
err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
|
2013-08-29 16:51:23 +08:00
|
|
|
return
|
|
|
|
}
|
2013-08-30 12:36:57 +08:00
|
|
|
|
|
|
|
// Error handler
|
|
|
|
type ErrorHandler func(error)
|