diff --git a/jsonrpc2/messages.go b/jsonrpc2/messages.go index 652ac817a..1f875f3c8 100644 --- a/jsonrpc2/messages.go +++ b/jsonrpc2/messages.go @@ -92,23 +92,23 @@ func NewResponse(id ID, result interface{}, rerr error) (*Response, error) { func (msg *Response) marshal(to *wireCombined) { to.ID = msg.ID.value - to.Error = toWireError(msg.Error) + to.Error = toError(msg.Error) to.Result = msg.Result } -func toWireError(err error) *wireError { +func toError(err error) *Error { if err == nil { // no error, the response is complete return nil } - if err, ok := err.(*wireError); ok { - // already a wire error, just use it + if err, ok := err.(*Error); ok { + // already an Error, just use it return err } - result := &wireError{Message: err.Error()} - var wrapped *wireError + result := &Error{Message: err.Error()} + var wrapped *Error if errors.As(err, &wrapped) { - // if we wrapped a wire error, keep the code from the wrapped error + // if we wrapped an Error, keep the code from the wrapped error // but the message from the outer error result.Code = wrapped.Code } diff --git a/jsonrpc2/wire.go b/jsonrpc2/wire.go index 4971a92d2..83c26290d 100644 --- a/jsonrpc2/wire.go +++ b/jsonrpc2/wire.go @@ -45,11 +45,11 @@ type wireCombined struct { Method string `json:"method,omitempty"` Params json.RawMessage `json:"params,omitempty"` Result json.RawMessage `json:"result,omitempty"` - Error *wireError `json:"error,omitempty"` + Error *Error `json:"error,omitempty"` } -// wireError represents a structured error in a Response. -type wireError struct { +// Error represents a structured error in a Response. +type Error struct { // Code is an error code indicating the type of failure. Code int64 `json:"code"` // Message is a short description of the error. @@ -63,12 +63,12 @@ type wireError struct { // only be used to build errors for application specific codes as allowed by the // specification. func NewError(code int64, message string) error { - return &wireError{ + return &Error{ Code: code, Message: message, } } -func (err *wireError) Error() string { +func (err *Error) Error() string { return err.Message }