rpc-go/protocol/error.go
crusader 8587e2e369 ing
2018-04-03 17:58:26 +09:00

36 lines
880 B
Go

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)
}