2020-03-24 14:15:01 +01:00
|
|
|
package middleware
|
2020-03-23 07:01:59 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-27 01:01:45 +02:00
|
|
|
|
2020-03-23 07:01:59 +01:00
|
|
|
"google.golang.org/grpc"
|
2020-03-24 14:15:01 +01:00
|
|
|
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/gerrors"
|
2022-04-27 01:01:45 +02:00
|
|
|
_ "github.com/zitadel/zitadel/internal/statik"
|
2020-03-23 07:01:59 +01:00
|
|
|
)
|
|
|
|
|
2020-08-28 09:44:43 +02: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) {
|
2020-08-28 09:44:43 +02:00
|
|
|
return toGRPCError(ctx, req, handler)
|
2020-03-23 07:01:59 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-08 13:56:37 +02:00
|
|
|
|
2020-08-28 09:44:43 +02:00
|
|
|
func toGRPCError(ctx context.Context, req interface{}, handler grpc.UnaryHandler) (interface{}, error) {
|
2020-07-08 13:56:37 +02:00
|
|
|
resp, err := handler(ctx, req)
|
2023-12-08 16:30:55 +02:00
|
|
|
return resp, gerrors.ZITADELToGRPCError(err)
|
2020-07-08 13:56:37 +02:00
|
|
|
}
|