From 1dfb77bfe11c98f5b6483134ef1155c0f804d920 Mon Sep 17 00:00:00 2001 From: songzhibin97 <49082129+songzhibin97@users.noreply.github.com> Date: Fri, 20 May 2022 18:51:09 +0800 Subject: [PATCH] Update errors.go (#2009) --- errors/errors.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/errors/errors.go b/errors/errors.go index f3031616e..a18f5512e 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -131,20 +131,20 @@ func FromError(err error) *Error { return se } gs, ok := status.FromError(err) - if ok { - ret := New( - httpstatus.FromGRPCCode(gs.Code()), - UnknownReason, - gs.Message(), - ) - for _, detail := range gs.Details() { - switch d := detail.(type) { - case *errdetails.ErrorInfo: - ret.Reason = d.Reason - return ret.WithMetadata(d.Metadata) - } + if !ok { + return New(UnknownCode, UnknownReason, err.Error()) + } + ret := New( + httpstatus.FromGRPCCode(gs.Code()), + UnknownReason, + gs.Message(), + ) + for _, detail := range gs.Details() { + switch d := detail.(type) { + case *errdetails.ErrorInfo: + ret.Reason = d.Reason + return ret.WithMetadata(d.Metadata) } - return ret } - return New(UnknownCode, UnknownReason, err.Error()) + return ret }