From ea503d05835d504979a7e28e1bc98ce479481e10 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 5 Apr 2022 12:36:14 +0300 Subject: [PATCH] test error transfering from grpc server Signed-off-by: Vasiliy Tolstov --- error.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/error.go b/error.go index 634b8ff..57c2a5d 100644 --- a/error.go +++ b/error.go @@ -22,23 +22,19 @@ func microError(err error) error { return err } - // return first error from details - if details := s.Details(); len(details) > 0 { + details := s.Details() + switch len(details) { + case 0: + return err + case 1: if verr, ok := details[0].(error); ok { return microError(verr) } - } - - // try to decode micro *errors.Error - if e := errors.Parse(s.Message()); e.Code > 0 { - return e // actually a micro error - } - - // fallback - return &errors.Error{ - ID: "go.micro.client", - Code: int32(s.Code()), - Detail: s.Message(), - Status: s.Code().String(), + return err + default: + if e := errors.Parse(s.Message()); e.Code > 0 { + return e // actually a micro error + } + return err } } -- 2.45.2