Skip to content

Commit

Permalink
Extend rpc header with a map for storing additional error information
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleasa committed Apr 4, 2019
1 parent d526b9f commit df35be2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Call struct {
type RequestError struct {
Message string
Code string
Info map[string]interface{}
}

func (e *RequestError) Error() string {
Expand Down Expand Up @@ -111,6 +112,7 @@ func (conn *Conn) handleResponse(hdr *Header) error {
call.Error = &RequestError{
Message: hdr.Error,
Code: hdr.ErrorCode,
Info: hdr.ErrorInfo,
}
err = conn.readBody(nil, false)
call.done()
Expand Down
4 changes: 2 additions & 2 deletions rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ func (root *Root) assertServerNotified(c *gc.C, p testCallParams, requestId uint
c.Assert(serverReply.body, gc.Equals, stringVal{p.request().Action + " ret"})
}
if p.retErr && p.testErr {
c.Assert(serverReply.hdr, gc.Equals, rpc.Header{
c.Assert(serverReply.hdr, gc.DeepEquals, rpc.Header{
RequestId: requestId,
Error: p.errorMessage(),
Version: 1,
})
} else {
c.Assert(serverReply.hdr, gc.Equals, rpc.Header{
c.Assert(serverReply.hdr, gc.DeepEquals, rpc.Header{
RequestId: requestId,
Version: 1,
})
Expand Down
4 changes: 4 additions & 0 deletions rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type Header struct {
// ErrorCode holds the code of the error, if any.
ErrorCode string

// ErrorInfo holds an optional set of additional information for an
// error, if any.
ErrorInfo map[string]interface{}

// Version defines the wire format of the request and response structure.
Version int
}
Expand Down

0 comments on commit df35be2

Please sign in to comment.