-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy patherror.go
73 lines (63 loc) · 1.68 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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
package jsonrpc
import "fmt"
const (
// ErrorCodeParse is parse error code.
ErrorCodeParse ErrorCode = -32700
// ErrorCodeInvalidRequest is invalid request error code.
ErrorCodeInvalidRequest ErrorCode = -32600
// ErrorCodeMethodNotFound is method not found error code.
ErrorCodeMethodNotFound ErrorCode = -32601
// ErrorCodeInvalidParams is invalid params error code.
ErrorCodeInvalidParams ErrorCode = -32602
// ErrorCodeInternal is internal error code.
ErrorCodeInternal ErrorCode = -32603
)
type (
// A ErrorCode by JSON-RPC 2.0.
ErrorCode int
// An Error is a wrapper for a JSON interface value.
Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
)
// Error implements error interface.
func (e *Error) Error() string {
return fmt.Sprintf("jsonrpc: code: %d, message: %s, data: %+v", e.Code, e.Message, e.Data)
}
// ErrParse returns parse error.
func ErrParse() *Error {
return &Error{
Code: ErrorCodeParse,
Message: "Parse error",
}
}
// ErrInvalidRequest returns invalid request error.
func ErrInvalidRequest() *Error {
return &Error{
Code: ErrorCodeInvalidRequest,
Message: "Invalid Request",
}
}
// ErrMethodNotFound returns method not found error.
func ErrMethodNotFound() *Error {
return &Error{
Code: ErrorCodeMethodNotFound,
Message: "Method not found",
}
}
// ErrInvalidParams returns invalid params error.
func ErrInvalidParams() *Error {
return &Error{
Code: ErrorCodeInvalidParams,
Message: "Invalid params",
}
}
// ErrInternal returns internal error.
func ErrInternal() *Error {
return &Error{
Code: ErrorCodeInternal,
Message: "Internal error",
}
}