From 4940da4326ff787dd43fc486f06be415257181ae Mon Sep 17 00:00:00 2001 From: Julien Tant Date: Fri, 14 Mar 2025 12:14:45 -0700 Subject: [PATCH] manage error the same way property field and value do --- server/i18n/en.json | 16 ++++------------ server/public/model/custom_profile_attributes.go | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/server/i18n/en.json b/server/i18n/en.json index b743fdc8b0c..bad4dcca7c7 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -5034,10 +5034,6 @@ "id": "app.custom_profile_attributes.get_property_field.app_error", "translation": "Unable to get Custom Profile Attribute field" }, - { - "id": "app.custom_profile_attributes.invalid_options.app_error", - "translation": "Unable to validate the options" - }, { "id": "app.custom_profile_attributes.limit_reached.app_error", "translation": "Custom Profile Attributes field limit reached" @@ -5066,18 +5062,14 @@ "id": "app.custom_profile_attributes.property_value_upsert.app_error", "translation": "Unable to upsert Custom Profile Attribute fields" }, + { + "id": "app.custom_profile_attributes.sanitize_and_validate.app_error", + "translation": "Invalid property value attributes : {{.AttributeName}} ({{.Reason}})." + }, { "id": "app.custom_profile_attributes.search_property_fields.app_error", "translation": "Unable to search Custom Profile Attribute fields" }, - { - "id": "app.custom_profile_attributes.unknown_value_type.app_error", - "translation": "The value type '{{.ValueType}}' is not supported" - }, - { - "id": "app.custom_profile_attributes.unknown_visibility.app_error", - "translation": "The visibility '{{.Visibility}}' is not supported" - }, { "id": "app.delete_scheduled_post.delete_error", "translation": "Failed to delete scheduled post from database." diff --git a/server/public/model/custom_profile_attributes.go b/server/public/model/custom_profile_attributes.go index 8b7253d7c85..950fc999956 100644 --- a/server/public/model/custom_profile_attributes.go +++ b/server/public/model/custom_profile_attributes.go @@ -136,7 +136,10 @@ func (c *CPAField) SanitizeAndValidate() *AppError { case PropertyFieldTypeText: if valueType := strings.TrimSpace(c.Attrs.ValueType); valueType != "" { if !IsKnownCPAValueType(valueType) { - return NewAppError("ValidateCPAField", "app.custom_profile_attributes.unknown_value_type.app_error", map[string]any{"ValueType": valueType}, "", http.StatusUnprocessableEntity) + return NewAppError("SanitizeAndValidate", "app.custom_profile_attributes.sanitize_and_validate.app_error", map[string]any{ + "AttributeName": CustomProfileAttributesPropertyAttrsValueType, + "Reason": "unknown value type", + }, "", http.StatusUnprocessableEntity) } c.Attrs.ValueType = valueType } @@ -152,7 +155,10 @@ func (c *CPAField) SanitizeAndValidate() *AppError { } if err := options.IsValid(); err != nil { - return NewAppError("ValidateCPAField", "app.custom_profile_attributes.invalid_options.app_error", nil, "", http.StatusUnprocessableEntity).Wrap(err) + return NewAppError("SanitizeAndValidate", "app.custom_profile_attributes.sanitize_and_validate.app_error", map[string]any{ + "AttributeName": PropertyFieldAttributeOptions, + "Reason": err.Error(), + }, "", http.StatusUnprocessableEntity).Wrap(err) } c.Attrs.Options = options } @@ -160,7 +166,10 @@ func (c *CPAField) SanitizeAndValidate() *AppError { visibility := CustomProfileAttributesVisibilityDefault if visibilityAttr := strings.TrimSpace(c.Attrs.Visibility); visibilityAttr != "" { if !IsKnownCPAVisibility(visibilityAttr) { - return NewAppError("ValidateCPAField", "app.custom_profile_attributes.unknown_visibility.app_error", map[string]any{"Visibility": visibilityAttr}, "", http.StatusUnprocessableEntity) + return NewAppError("SanitizeAndValidate", "app.custom_profile_attributes.sanitize_and_validate.app_error", map[string]any{ + "AttributeName": CustomProfileAttributesPropertyAttrsVisibility, + "Reason": "unknown visibility", + }, "", http.StatusUnprocessableEntity) } visibility = visibilityAttr }