zitadel/internal/api/grpc/server/middleware/error_interceptor.go
Fabi 6556d053b2
feat: translate error messages (#254)
* feat: translate error messages in error interceptor

* fix: add statik import

* feat: user error msgs

* feat: add translations

* feat: add translations

* feat: add translations

* feat: add translations

* feat: add translations

* feat: add translations

* some fixes and improved error messages

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2020-06-22 13:51:44 +02:00

30 lines
1017 B
Go

package middleware
import (
"context"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/i18n"
"github.com/rakyll/statik/fs"
"golang.org/x/text/language"
"google.golang.org/grpc"
grpc_util "github.com/caos/zitadel/internal/api/grpc"
_ "github.com/caos/zitadel/internal/statik"
)
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")
}
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
return resp, grpc_util.CaosToGRPCError(err, ctx, i18n)
}
}