mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
31 lines
504 B
Go
31 lines
504 B
Go
package grpc
|
|
|
|
import (
|
|
"github.com/micro/go-micro/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
|
|
}
|