-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
59 lines (48 loc) · 1.69 KB
/
errors.go
File metadata and controls
59 lines (48 loc) · 1.69 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
package jsonrpc
import "errors"
var ErrTransportClosed = errors.New("transport closed")
// ErrInvalidParams is returned when the params of a request are invalid.
var ErrInvalidParams error = newRpcErr(nil, invalidParamsErr, "Invalid params")
// ErrInternal is returned when an internal error occurs in a handler or the
var ErrInternal error = newRpcErr(nil, internalErr, "Internal error")
// error factories for internal use
var errParseError = newRpcErr(nil, jsonParseErr, "Parse error")
var errInvalidRequest = newRpcErr(nil, invalidRequestErr, "Invalid Request")
var errMethodNotFound = func(id string) *RPCErr { return newRpcErr(&id, methodNotFoundErr, "Method not found") }
var errInvalidParams = func(id string) *RPCErr { return newRpcErr(&id, internalErr, "Invalid params") }
var errInternal = func(id string) *RPCErr { return newRpcErr(&id, internalErr, "Internal error") }
var ErrMethodAlreadyRegistered = errors.New("Method already registered")
var ErrAlreadySubscribed = errors.New("Already subscribed")
const jsonParseErr = -32700
const invalidRequestErr = -32600
const methodNotFoundErr = -32601
const invalidParamsErr = -32602
const internalErr = -32603
type RPCErr struct {
code int
id *string
message string
}
func (e *RPCErr) Error() string {
return e.message
}
func (e *RPCErr) Code() int {
return e.code
}
func (e *RPCErr) ID() string {
if e.id == nil {
return ""
}
return *e.id
}
// NewRPCErr creates a new RPC error with the given code, and message.
func NewRPCErr(code int, message string) *RPCErr {
return newRpcErr(nil, code, message)
}
func newRpcErr(id *string, code int, message string) *RPCErr {
return &RPCErr{
code: code,
message: message,
id: id,
}
}