micro-client-grpc/error.go
Vasiliy Tolstov 0807802cea fix import paths for v2 release
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-09-18 16:32:52 +03:00

31 lines
507 B
Go

package grpc
import (
"github.com/micro/go-micro/v2/errors"
"google.golang.org/grpc/status"
)
func microError(err error) error {
// no error
switch err {
case nil:
return nil
}
// micro error
if v, ok := err.(*errors.Error); ok {
return v
}
// grpc error
if s, ok := status.FromError(err); ok {
if e := errors.Parse(s.Message()); e.Code > 0 {
return e // actually a micro error
}
return errors.InternalServerError("go.micro.client", s.Message())
}
// do nothing
return err
}