|
|
|
@ -18,20 +18,27 @@ package rpc |
|
|
|
|
|
|
|
|
|
import "fmt" |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
_ ErrorWithCode = new(methodNotFoundError) |
|
|
|
|
_ ErrorWithCode = new(subscriptionNotFoundError) |
|
|
|
|
_ ErrorWithCode = new(parseError) |
|
|
|
|
_ ErrorWithCode = new(invalidRequestError) |
|
|
|
|
_ ErrorWithCode = new(invalidMessageError) |
|
|
|
|
_ ErrorWithCode = new(invalidParamsError) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const defaultErrorCode = -32000 |
|
|
|
|
|
|
|
|
|
type methodNotFoundError struct{ method string } |
|
|
|
|
|
|
|
|
|
func (e *methodNotFoundError) ErrorCode() int { return -32601 } |
|
|
|
|
|
|
|
|
|
func (e *methodNotFoundError) Code() int { return -32601 } |
|
|
|
|
func (e *methodNotFoundError) Error() string { |
|
|
|
|
return fmt.Sprintf("the method %s does not exist/is not available", e.method) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type subscriptionNotFoundError struct{ namespace, subscription string } |
|
|
|
|
|
|
|
|
|
func (e *subscriptionNotFoundError) ErrorCode() int { return -32601 } |
|
|
|
|
|
|
|
|
|
func (e *subscriptionNotFoundError) Code() int { return -32601 } |
|
|
|
|
func (e *subscriptionNotFoundError) Error() string { |
|
|
|
|
return fmt.Sprintf("no %q subscription in %s namespace", e.subscription, e.namespace) |
|
|
|
|
} |
|
|
|
@ -39,27 +46,23 @@ func (e *subscriptionNotFoundError) Error() string { |
|
|
|
|
// Invalid JSON was received by the server.
|
|
|
|
|
type parseError struct{ message string } |
|
|
|
|
|
|
|
|
|
func (e *parseError) ErrorCode() int { return -32700 } |
|
|
|
|
|
|
|
|
|
func (e *parseError) Code() int { return -32700 } |
|
|
|
|
func (e *parseError) Error() string { return e.message } |
|
|
|
|
|
|
|
|
|
// received message isn't a valid request
|
|
|
|
|
type invalidRequestError struct{ message string } |
|
|
|
|
|
|
|
|
|
func (e *invalidRequestError) ErrorCode() int { return -32600 } |
|
|
|
|
|
|
|
|
|
func (e *invalidRequestError) Code() int { return -32600 } |
|
|
|
|
func (e *invalidRequestError) Error() string { return e.message } |
|
|
|
|
|
|
|
|
|
// received message is invalid
|
|
|
|
|
type invalidMessageError struct{ message string } |
|
|
|
|
|
|
|
|
|
func (e *invalidMessageError) ErrorCode() int { return -32700 } |
|
|
|
|
|
|
|
|
|
func (e *invalidMessageError) Code() int { return -32700 } |
|
|
|
|
func (e *invalidMessageError) Error() string { return e.message } |
|
|
|
|
|
|
|
|
|
// unable to decode supplied params, or an invalid number of parameters
|
|
|
|
|
type invalidParamsError struct{ message string } |
|
|
|
|
|
|
|
|
|
func (e *invalidParamsError) ErrorCode() int { return -32602 } |
|
|
|
|
|
|
|
|
|
func (e *invalidParamsError) Code() int { return -32602 } |
|
|
|
|
func (e *invalidParamsError) Error() string { return e.message } |
|
|
|
|