-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
34 lines (29 loc) · 1.18 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package rpc
import "fmt"
var (
ParseError = NewError(-32700, "Invalid JSON was received by the server")
InvalidRequest = NewError(-32600, "The JSON sent is not a valid Request object")
MethodNotFound = NewError(-32601, "The method does not exist / is not available")
InvalidMethodParam = NewError(-32602, "Invalid method parameter(s)")
InternalError = NewError(-32602, "Internal JSON-RPC error")
ExecutionTimeoutError = NewError(-32001, "Execution Timeout")
RequestBodyIsEmpty = NewError(-32002, "Request body is empty")
RequestBodyTooLargeError = NewError(-32003, "Request body too large")
InvalidRpcVersion = NewError(-32004, "Invalid RPC Version")
)
// Error is a JSON RPC Spec Error Object that hold the error code and the message.
// Spec - https://www.jsonrpc.org/specification#error_object
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
}
// NewError creates and Error from a code and a message
func NewError(code int, msg string) Error {
return Error{
Code: code,
Message: msg,
}
}
func (e Error) Error() string {
return fmt.Sprintf("rpc error [%d] %s", e.Code, e.Message)
}