rpc/protocol/error.go

36 lines
880 B
Go
Raw Permalink Normal View History

2018-03-20 06:31:54 +00:00
package protocol
2018-03-27 11:23:43 +00:00
import (
"errors"
"fmt"
)
2018-03-20 06:31:54 +00:00
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
)
2018-03-27 11:23:43 +00:00
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)
}