1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-25 21:38:59 +02:00

Update errors.go (#2009)

This commit is contained in:
songzhibin97 2022-05-20 18:51:09 +08:00 committed by GitHub
parent ef6fb480c6
commit 1dfb77bfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}
}
return ret
if !ok {
return New(UnknownCode, UnknownReason, err.Error())
}
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
}