-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
60 lines (50 loc) · 1.1 KB
/
error.go
File metadata and controls
60 lines (50 loc) · 1.1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package jsonrpc
import "fmt"
const (
ErrorCodeParse ErrorCode = -32700
ErrorCodeInvalidRequest ErrorCode = -32600
ErrorCodeMethodNotFound ErrorCode = -32601
ErrorCodeInvalidParams ErrorCode = -32602
ErrorCodeInternal ErrorCode = -32603
)
type (
ErrorCode int
Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
)
func (e *Error) Error() string {
return fmt.Sprintf("jsonrpc: code: %d, message: %s, data: %+v", e.Code, e.Message, e.Data)
}
func ErrParse() *Error {
return &Error{
Code: ErrorCodeParse,
Message: "Parse error",
}
}
func ErrInvalidRequest() *Error {
return &Error{
Code: ErrorCodeInvalidRequest,
Message: "Invalid Request",
}
}
func ErrMethodNotFound() *Error {
return &Error{
Code: ErrorCodeMethodNotFound,
Message: "Method not found",
}
}
func ErrInvalidParams() *Error {
return &Error{
Code: ErrorCodeInvalidParams,
Message: "Invalid params",
}
}
func ErrInternal() *Error {
return &Error{
Code: ErrorCodeInternal,
Message: "Internal error",
}
}