2020-03-24 13:15:01 +00:00
|
|
|
package middleware
|
2020-03-23 06:01:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-26 23:01:45 +00:00
|
|
|
|
2020-03-23 06:01:59 +00:00
|
|
|
"google.golang.org/grpc"
|
2020-03-24 13:15:01 +00:00
|
|
|
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/gerrors"
|
2022-04-26 23:01:45 +00:00
|
|
|
_ "github.com/zitadel/zitadel/internal/statik"
|
2020-03-23 06:01:59 +00:00
|
|
|
)
|
|
|
|
|
2020-08-28 07:44:43 +00:00
|
|
|
func ErrorHandler() grpc.UnaryServerInterceptor {
|
2020-03-23 06:01:59 +00:00
|
|
|
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
2020-08-28 07:44:43 +00:00
|
|
|
return toGRPCError(ctx, req, handler)
|
2020-03-23 06:01:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-08 11:56:37 +00:00
|
|
|
|
2020-08-28 07:44:43 +00:00
|
|
|
func toGRPCError(ctx context.Context, req interface{}, handler grpc.UnaryHandler) (interface{}, error) {
|
2020-07-08 11:56:37 +00:00
|
|
|
resp, err := handler(ctx, req)
|
2023-12-08 14:30:55 +00:00
|
|
|
return resp, gerrors.ZITADELToGRPCError(err)
|
2020-07-08 11:56:37 +00:00
|
|
|
}
|