Compare commits

...

1 Commits

Author SHA1 Message Date
stasatdaglabs
b73d9f4045 [NOD-1367] Add an error handler to GRPCClient. 2020-09-10 14:08:19 +03:00

View File

@@ -12,9 +12,12 @@ import (
"time"
)
type OnErrorHandler func(err error)
// GRPCClient is a gRPC-based RPC client
type GRPCClient struct {
stream protowire.RPC_MessageStreamClient
stream protowire.RPC_MessageStreamClient
onErrorHandler OnErrorHandler
}
// Connect connects to the RPC server with the given address
@@ -41,6 +44,10 @@ func (c *GRPCClient) Disconnect() error {
return c.stream.CloseSend()
}
func (c *GRPCClient) SetOnErrorHandler(onErrorHandler OnErrorHandler) {
c.onErrorHandler = onErrorHandler
}
// AttachRouter attaches the given router to the client and starts
// sending/receiving messages via it
func (c *GRPCClient) AttachRouter(router *router.Router) {
@@ -101,5 +108,9 @@ func (c *GRPCClient) handleError(err error) {
}
return
}
if c.onErrorHandler != nil {
c.onErrorHandler(err)
return
}
panic(err)
}