forked from poseidon/matchbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
30 lines (26 loc) · 771 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package rpc
import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"github.com/coreos/matchbox/matchbox/server"
)
var (
// work around go vet false positive https://github.com/grpc/grpc-go/issues/90
grpcErrorf = grpc.Errorf
errNoMatchingGroup = grpcErrorf(codes.NotFound, "matchbox: No matching Group")
errNoMatchingProfile = grpcErrorf(codes.NotFound, "matchbox: No matching Profile")
)
// grpcError transforms an error into a gRPC errors with canonical error codes.
func grpcError(err error) error {
if err == nil {
return err
}
switch err {
case server.ErrNoMatchingGroup:
return errNoMatchingGroup
case server.ErrNoMatchingProfile:
return errNoMatchingProfile
default:
return grpcErrorf(codes.Unknown, err.Error())
}
}