zitadel/internal/api/grpc/server/middleware/error_interceptor.go

22 lines
585 B
Go
Raw Normal View History

2020-03-24 14:15:01 +01:00
package middleware
2020-03-23 07:01:59 +01:00
import (
"context"
2020-03-23 07:01:59 +01:00
"google.golang.org/grpc"
2020-03-24 14:15:01 +01:00
"github.com/zitadel/zitadel/internal/api/grpc/gerrors"
_ "github.com/zitadel/zitadel/internal/statik"
2020-03-23 07:01:59 +01:00
)
func ErrorHandler() grpc.UnaryServerInterceptor {
2020-03-23 07:01:59 +01:00
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return toGRPCError(ctx, req, handler)
2020-03-23 07:01:59 +01:00
}
}
func toGRPCError(ctx context.Context, req interface{}, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
return resp, gerrors.ZITADELToGRPCError(err)
}