From fdd59717c8cc8e419817ddea145a91ef7601d35a Mon Sep 17 00:00:00 2001 From: Brecci Date: Mon, 2 Dec 2024 19:34:40 -0300 Subject: [PATCH] fix(account): add error message translation for prohibited external account creation and adjust validation assertion :bug: --- pkg/net/http/withBody.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/net/http/withBody.go b/pkg/net/http/withBody.go index af64b954..b29b06ec 100644 --- a/pkg/net/http/withBody.go +++ b/pkg/net/http/withBody.go @@ -272,6 +272,15 @@ func newValidator() (*validator.Validate, ut.Translator) { return t }) + _ = v.RegisterTranslation("prohibitedexternalaccountprefix", trans, func(ut ut.Translator) error { + prefix := cn.DefaultExternalAccountAliasPrefix + return ut.Add("prohibitedexternalaccountprefix", "{0} cannot contain the text '"+prefix+"'", true) + }, func(ut ut.Translator, fe validator.FieldError) string { + t, _ := ut.T("prohibitedexternalaccountprefix", formatErrorFieldName(fe.Namespace())) + + return t + }) + return v, trans } @@ -354,7 +363,7 @@ func validateSingleTransactionType(fl validator.FieldLevel) bool { func validateProhibitedExternalAccountPrefix(fl validator.FieldLevel) bool { f := fl.Field().Interface().(string) - return strings.Contains(f, cn.DefaultExternalAccountAliasPrefix) + return !strings.Contains(f, cn.DefaultExternalAccountAliasPrefix) } // formatErrorFieldName formats metadata field error names for error messages