-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
115 lines (78 loc) · 2.97 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
105
106
107
108
109
110
111
112
113
114
115
package errors
import (
"fmt"
)
const (
// Use the same error code with Aurora Plus infra
TxsStatus = 3
// -32000 to -32768 are reserved for pre-defined errors by JSON-RPC standard.
Generic = -32000
LogRangeLimitExceeded = -32005
InvalidRequest = -32600
MethodNotFound = -32601
InvalidParams = -32602
Internal = -32603
ParseError = -32700
// -32900 to -32999 space is reserved for Aurora Relayer application specific errors.
KeyNotFound = -32900
)
type Error interface {
Error() string // returns the message
ErrorCode() int // returns the code
}
type DataError interface {
Error() string // returns the message
ErrorData() string // returns the error data
}
type MethodNotFoundError struct{ Method string }
func (e *MethodNotFoundError) ErrorCode() int { return MethodNotFound }
func (e *MethodNotFoundError) Error() string {
return fmt.Sprintf("the method %s does not exist/is not available", e.Method)
}
// received rpc request not valid
type InvalidRequestError struct{ Message string }
func (e *InvalidRequestError) ErrorCode() int { return InvalidRequest }
func (e *InvalidRequestError) Error() string { return e.Message }
// received rpc request parameters not valid
type InvalidParamsError struct{ Message string }
func (e *InvalidParamsError) ErrorCode() int { return InvalidParams }
func (e *InvalidParamsError) Error() string { return e.Message }
// provided event subscription method does not exist
type SubscriptionNotFoundError struct{ Subscription string }
func (e *SubscriptionNotFoundError) ErrorCode() int { return -32601 }
func (e *SubscriptionNotFoundError) Error() string {
return fmt.Sprintf("no %q subscription found", e.Subscription)
}
type GenericError struct{ Err error }
func (e *GenericError) ErrorCode() int {
err, ok := e.Err.(Error)
if ok {
return err.ErrorCode()
}
return Generic
}
func (e *GenericError) Error() string { return e.Err.Error() }
type KeyNotFoundError struct{}
func (e *KeyNotFoundError) ErrorCode() int { return KeyNotFound }
func (e *KeyNotFoundError) Error() string {
return "record not found in DB"
}
type LogResponseRangeLimitError struct{ Err error }
func (e *LogResponseRangeLimitError) ErrorCode() int { return LogRangeLimitExceeded }
func (e *LogResponseRangeLimitError) Error() string { return e.Err.Error() }
type TxsStatusError struct{ Message string }
func (e *TxsStatusError) ErrorCode() int { return TxsStatus }
func (e *TxsStatusError) Error() string { return e.Message }
type TxsRevertError struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
}
func (e *TxsRevertError) ErrorCode() int { return e.Code }
func (e *TxsRevertError) Error() string { return e.Message }
func (e *TxsRevertError) ErrorData() string { return e.Data }
type InternalError struct{ Message string }
func (e *InternalError) ErrorCode() int { return Internal }
func (e *InternalError) Error() string {
return e.Message
}