From b1ea7b89837bc027708deb40c92a4042e5ccf1c2 Mon Sep 17 00:00:00 2001 From: Yao <34502305+yaoding16@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:44:19 +0800 Subject: [PATCH 1/2] refactor: modify ClientErrorFunc Add response message parameters to the ClientErrorFunc function, It can be consistent with the ServerErrorFunc function signature and make custom biz errors more flexible --- client/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index 53f91399..f7b05abe 100644 --- a/client/client.go +++ b/client/client.go @@ -46,7 +46,7 @@ func NewServiceError(s string) ServiceError { } // ClientErrorFunc is a function to create a customized error. -var ClientErrorFunc func(e string) ServiceError +var ClientErrorFunc func(res *protocol.Message, , e string) ServiceError type strErr string @@ -663,7 +663,7 @@ func (client *Client) input() { // convert server error to a customized error, which implements ServerError interface if ClientErrorFunc != nil { - call.Error = ClientErrorFunc(res.Metadata[protocol.ServiceError]) + call.Error = ClientErrorFunc(res, res.Metadata[protocol.ServiceError]) } else { call.Error = strErr(res.Metadata[protocol.ServiceError]) } From c057e03fed7da7ea970c0e34102e3e8512a70efe Mon Sep 17 00:00:00 2001 From: Yao <34502305+yaoding16@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:48:30 +0800 Subject: [PATCH 2/2] Update client.go --- client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index f7b05abe..5b121798 100644 --- a/client/client.go +++ b/client/client.go @@ -46,7 +46,7 @@ func NewServiceError(s string) ServiceError { } // ClientErrorFunc is a function to create a customized error. -var ClientErrorFunc func(res *protocol.Message, , e string) ServiceError +var ClientErrorFunc func(res *protocol.Message, e string) ServiceError type strErr string