Skip to content

Commit bc5ccd8

Browse files
committed
feat(client): prioritize BizStatusError in DefaultClientErrorHandler
1 parent ff85e39 commit bc5ccd8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

client/middlewares.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,17 @@ func newIOErrorHandleMW(errHandle func(context.Context, error) error) endpoint.M
161161

162162
// DefaultClientErrorHandler is Default ErrorHandler for client
163163
// when no ErrorHandler is specified with Option `client.WithErrorHandler`, this ErrorHandler will be injected.
164-
// for thrift、KitexProtobuf, >= v0.4.0 wrap protocol error to TransError, which will be more friendly.
164+
// For thrift、KitexProtobuf >= v0.4.0, wraps protocol error to TransError, which will be more friendly.
165+
// For thrift、KitexProtobuf >= v0.8.1, returns BizStatusError directly if it is set.
165166
func DefaultClientErrorHandler(ctx context.Context, err error) error {
167+
rpcInfo := rpcinfo.GetRPCInfo(ctx)
168+
// If BizStatusErr is not nil, it means that the business logic has been processed and the error has been set
169+
// and transmitted to the client. In this case, just return the bizErr directly.
170+
bizErr := rpcInfo.Invocation().BizStatusErr()
171+
if bizErr != nil {
172+
return bizErr
173+
}
174+
166175
switch err.(type) {
167176
// for thrift、KitexProtobuf, actually check *remote.TransError is enough
168177
case *remote.TransError, thrift.TApplicationException, protobuf.PBError:

0 commit comments

Comments
 (0)