rpc-go/protocol/error.go

36 lines
880 B
Go
Raw Normal View History

2018-08-22 09:04:25 +00:00
package protocol
import (
"errors"
"fmt"
)
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 {
// A Number that indicates the error type that occurred.
Code ErrorCode `json:"code"` /* required */
// A String providing a short description of the error.
// The message SHOULD be limited to a concise single sentence.
Message string `json:"message"` /* required */
// A Primitive or Structured value that contains additional information about the error.
Data interface{} `json:"data"` /* optional */
}
func (e Error) Error() string {
return fmt.Sprintf("Code[%d] Message[%s] Data[%v]", e.Code, e.Message, e.Data)
}