mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
38 lines
883 B
Go
38 lines
883 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/i18n"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
type localizers interface {
|
|
Localizers() []Localizer
|
|
}
|
|
type Localizer interface {
|
|
LocalizationKey() string
|
|
SetLocalizedMessage(string)
|
|
}
|
|
|
|
func translateFields(ctx context.Context, object localizers, translator *i18n.Translator) {
|
|
if translator == nil || object == nil {
|
|
return
|
|
}
|
|
for _, field := range object.Localizers() {
|
|
field.SetLocalizedMessage(translator.LocalizeFromCtx(ctx, field.LocalizationKey(), nil))
|
|
}
|
|
}
|
|
|
|
func translateError(ctx context.Context, err error, translator *i18n.Translator) error {
|
|
if translator == nil || err == nil {
|
|
return err
|
|
}
|
|
caosErr := new(zerrors.ZitadelError)
|
|
if errors.As(err, &caosErr) {
|
|
caosErr.SetMessage(translator.LocalizeFromCtx(ctx, caosErr.GetMessage(), nil))
|
|
}
|
|
return err
|
|
}
|