crusader f49a711b5a ing
2017-07-13 21:01:28 +09:00

36 lines
677 B
Go

package protocol
import "errors"
type ErrorCode int
const (
E_PARSE ErrorCode = -32700
E_INVALID_REQ ErrorCode = -32600
E_NO_METHOD ErrorCode = -32601
E_BAD_PARAMS ErrorCode = -32602
E_INTERNAL ErrorCode = -32603
E_SERVER ErrorCode = -32000
)
var ErrNullResult = errors.New("result is null")
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
type Handler interface {
Handle([]byte) ([]byte, *Error)
}
func NewError(code ErrorCode, err error, data interface{}) *Error {
e := &Error{
Code: code,
Message: err.Error(),
Data: data,
}
return e
}