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