2020-03-24 13:15:01 +00:00
|
|
|
package middleware
|
2020-03-23 06:01:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-22 11:51:44 +00:00
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/caos/zitadel/internal/i18n"
|
|
|
|
"github.com/rakyll/statik/fs"
|
|
|
|
"golang.org/x/text/language"
|
2020-03-23 06:01:59 +00:00
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
2020-03-24 13:15:01 +00:00
|
|
|
|
|
|
|
grpc_util "github.com/caos/zitadel/internal/api/grpc"
|
2020-06-22 11:51:44 +00:00
|
|
|
_ "github.com/caos/zitadel/internal/statik"
|
2020-03-23 06:01:59 +00:00
|
|
|
)
|
|
|
|
|
2020-06-22 11:51:44 +00:00
|
|
|
func ErrorHandler(defaultLanguage language.Tag) func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
|
|
|
dir, err := fs.NewWithNamespace("zitadel")
|
|
|
|
logging.Log("ERROR-7usEW").OnError(err).Panic("unable to get zitadel namespace")
|
|
|
|
|
|
|
|
i18n, err := i18n.NewTranslator(dir, i18n.TranslatorConfig{DefaultLanguage: defaultLanguage})
|
|
|
|
if err != nil {
|
|
|
|
logging.Log("ERROR-Sk8sf").OnError(err).Panic("unable to get i18n translator")
|
|
|
|
}
|
|
|
|
|
2020-03-23 06:01:59 +00:00
|
|
|
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
|
|
|
resp, err := handler(ctx, req)
|
2020-06-22 11:51:44 +00:00
|
|
|
return resp, grpc_util.CaosToGRPCError(err, ctx, i18n)
|
2020-03-23 06:01:59 +00:00
|
|
|
}
|
|
|
|
}
|