/
errors.go
104 lines (81 loc) · 1.98 KB
/
errors.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package jsonrpc
import (
"errors"
"fmt"
"github.com/alveycoin/alveychain/state/runtime"
"github.com/umbracle/ethgo/abi"
)
var (
ErrStateNotFound = errors.New("given root and slot not found in storage")
)
type Error interface {
Error() string
ErrorCode() int
}
type invalidParamsError struct {
err string
}
type internalError struct {
err string
}
func (e *internalError) Error() string {
return e.err
}
func (e *internalError) ErrorCode() int {
return -32603
}
func (e *invalidParamsError) Error() string {
return e.err
}
func (e *invalidParamsError) ErrorCode() int {
return -32602
}
type invalidRequestError struct {
err string
}
func (e *invalidRequestError) Error() string {
return e.err
}
func (e *invalidRequestError) ErrorCode() int {
return -32600
}
type subscriptionNotFoundError struct {
err string
}
func (e *subscriptionNotFoundError) Error() string {
return e.err
}
func (e *subscriptionNotFoundError) ErrorCode() int {
return -32601
}
type methodNotFoundError struct {
err string
}
func (e *methodNotFoundError) Error() string {
return e.err
}
func (e *methodNotFoundError) ErrorCode() int {
return -32601
}
func NewMethodNotFoundError(method string) *methodNotFoundError {
return &methodNotFoundError{fmt.Sprintf("the method %s does not exist/is not available", method)}
}
func NewInvalidRequestError(msg string) *invalidRequestError {
return &invalidRequestError{msg}
}
func NewInvalidParamsError(msg string) *invalidParamsError {
return &invalidParamsError{msg}
}
func NewInternalError(msg string) *internalError {
return &internalError{msg}
}
func NewSubscriptionNotFoundError(method string) *subscriptionNotFoundError {
return &subscriptionNotFoundError{fmt.Sprintf("subscribe method %s not found", method)}
}
func constructErrorFromRevert(result *runtime.ExecutionResult) error {
revertErrMsg, unpackErr := abi.UnpackRevertError(result.ReturnValue)
if unpackErr != nil {
return result.Err
}
return fmt.Errorf("%w: %s", result.Err, revertErrMsg)
}