...
1 package jsonrpc
2
3
4
5
6 type Error struct {
7 Code int `json:"code"`
8 Message string `json:"message"`
9 Data interface{} `json:"data,omitempty"`
10 }
11
12
13 func (e Error) Error() string {
14 if e.Message != "" {
15 return e.Message
16 }
17 return errorMessage[e.Code]
18 }
19
20
21 func (e Error) ErrorCode() int {
22 return e.Code
23 }
24
25 const (
26
27
28 ParseError int = -32700
29
30
31 InvalidRequestError int = -32600
32
33
34 MethodNotFoundError int = -32601
35
36
37 InvalidParamsError int = -32602
38
39
40 InternalError int = -32603
41 )
42
43 var errorMessage = map[int]string{
44 ParseError: "An error occurred on the server while parsing the JSON text.",
45 InvalidRequestError: "The JSON sent is not a valid Request object.",
46 MethodNotFoundError: "The method does not exist / is not available.",
47 InvalidParamsError: "Invalid method parameter(s).",
48 InternalError: "Internal JSON-RPC error.",
49 }
50
51
52
53 func ErrorMessage(code int) string {
54 return errorMessage[code]
55 }
56
57 type parseError string
58
59 func (e parseError) Error() string {
60 return string(e)
61 }
62 func (e parseError) ErrorCode() int {
63 return ParseError
64 }
65
66 type invalidRequestError string
67
68 func (e invalidRequestError) Error() string {
69 return string(e)
70 }
71 func (e invalidRequestError) ErrorCode() int {
72 return InvalidRequestError
73 }
74
75 type methodNotFoundError string
76
77 func (e methodNotFoundError) Error() string {
78 return string(e)
79 }
80 func (e methodNotFoundError) ErrorCode() int {
81 return MethodNotFoundError
82 }
83
84 type invalidParamsError string
85
86 func (e invalidParamsError) Error() string {
87 return string(e)
88 }
89 func (e invalidParamsError) ErrorCode() int {
90 return InvalidParamsError
91 }
92
93 type internalError string
94
95 func (e internalError) Error() string {
96 return string(e)
97 }
98 func (e internalError) ErrorCode() int {
99 return InternalError
100 }
101
View as plain text