Skip to content

Commit

Permalink
fix(account): add error message translation for prohibited external a…
Browse files Browse the repository at this point in the history
…ccount creation and adjust validation assertion 🐛
  • Loading branch information
qnen committed Dec 2, 2024
1 parent fef2192 commit fdd5971
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/net/http/withBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fdd5971

Please sign in to comment.