Skip to content

Commit 56e1a4e

Browse files
committed
jsonrpc2: wireError becomes Error
So Code & Data fields are available outside jsonrpc2 package.
1 parent de9c53c commit 56e1a4e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

jsonrpc2/messages.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,23 @@ func NewResponse(id ID, result interface{}, rerr error) (*Response, error) {
9292

9393
func (msg *Response) marshal(to *wireCombined) {
9494
to.ID = msg.ID.value
95-
to.Error = toWireError(msg.Error)
95+
to.Error = toError(msg.Error)
9696
to.Result = msg.Result
9797
}
9898

99-
func toWireError(err error) *wireError {
99+
func toError(err error) *Error {
100100
if err == nil {
101101
// no error, the response is complete
102102
return nil
103103
}
104-
if err, ok := err.(*wireError); ok {
105-
// already a wire error, just use it
104+
if err, ok := err.(*Error); ok {
105+
// already an Error, just use it
106106
return err
107107
}
108-
result := &wireError{Message: err.Error()}
109-
var wrapped *wireError
108+
result := &Error{Message: err.Error()}
109+
var wrapped *Error
110110
if errors.As(err, &wrapped) {
111-
// if we wrapped a wire error, keep the code from the wrapped error
111+
// if we wrapped an Error, keep the code from the wrapped error
112112
// but the message from the outer error
113113
result.Code = wrapped.Code
114114
}

jsonrpc2/wire.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type wireCombined struct {
4545
Method string `json:"method,omitempty"`
4646
Params json.RawMessage `json:"params,omitempty"`
4747
Result json.RawMessage `json:"result,omitempty"`
48-
Error *wireError `json:"error,omitempty"`
48+
Error *Error `json:"error,omitempty"`
4949
}
5050

51-
// wireError represents a structured error in a Response.
52-
type wireError struct {
51+
// Error represents a structured error in a Response.
52+
type Error struct {
5353
// Code is an error code indicating the type of failure.
5454
Code int64 `json:"code"`
5555
// Message is a short description of the error.
@@ -63,12 +63,12 @@ type wireError struct {
6363
// only be used to build errors for application specific codes as allowed by the
6464
// specification.
6565
func NewError(code int64, message string) error {
66-
return &wireError{
66+
return &Error{
6767
Code: code,
6868
Message: message,
6969
}
7070
}
7171

72-
func (err *wireError) Error() string {
72+
func (err *Error) Error() string {
7373
return err.Message
7474
}

0 commit comments

Comments
 (0)