diff --git a/app/constants.py b/app/constants.py index fb547ce263..bc297bf7bd 100644 --- a/app/constants.py +++ b/app/constants.py @@ -330,16 +330,3 @@ class CacheKeys: # Admin API error codes QR_CODE_TOO_LONG = "qr-code-too-long" - - -# We updated the content for phone number validation messages in https://github.com/alphagov/notifications-utils/pull/1054, -# but these are returned from our API. We don't want to make any breaking changes, so we will map them back to our -# original errors. -# We can decide as/when we want to remove this and update the messages to end users. -PHONE_NUMBER_VALIDATION_ERROR_MAP = { - "Mobile numbers can only include: 0 1 2 3 4 5 6 7 8 9 ( ) + -": "Must not contain letters or symbols", - "Mobile number is too long": "Too many digits", - "Mobile number is too short": "Not enough digits", - "Country code not found - double check the mobile number you entered": "Not a valid country prefix", - "This does not look like a UK mobile number – double check the mobile number you entered": "Not a UK mobile number", -} diff --git a/app/notifications/validators.py b/app/notifications/validators.py index d424ebb7b3..857c8ea8f9 100644 --- a/app/notifications/validators.py +++ b/app/notifications/validators.py @@ -21,7 +21,6 @@ KEY_TYPE_TEAM, KEY_TYPE_TEST, LETTER_TYPE, - PHONE_NUMBER_VALIDATION_ERROR_MAP, SMS_TYPE, ) from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id @@ -277,7 +276,3 @@ def check_template_can_contain_documents(template_type, personalisation): isinstance(v, dict) and "file" in v for v in (personalisation or {}).values() ): raise BadRequestError(message="Can only send a file by email") - - -def remap_phone_number_validation_messages(error_message): - return PHONE_NUMBER_VALIDATION_ERROR_MAP.get(error_message, error_message) diff --git a/app/schemas.py b/app/schemas.py index 8c7a556266..2e8a66a786 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -25,7 +25,6 @@ from app import db, ma, models from app.dao.permissions_dao import permission_dao from app.models import ServicePermission -from app.notifications.validators import remap_phone_number_validation_messages from app.utils import DATETIME_FORMAT_NO_TIMEZONE, get_template_instance @@ -134,8 +133,7 @@ def validate_mobile_number(self, value): if value is not None: validate_phone_number(value, international=True) except InvalidPhoneError as error: - error_message = remap_phone_number_validation_messages(str(error)) - raise ValidationError(f"Invalid phone number: {error_message}") from error + raise ValidationError(f"Invalid phone number: {error.get_legacy_v2_api_error_message()}") from error class UserUpdateAttributeSchema(BaseSchema): @@ -175,8 +173,7 @@ def validate_mobile_number(self, value): if value is not None: validate_phone_number(value, international=True) except InvalidPhoneError as error: - error_message = remap_phone_number_validation_messages(str(error)) - raise ValidationError(f"Invalid phone number: {error_message}") from error + raise ValidationError(f"Invalid phone number: {error.get_legacy_v2_api_error_message()}") from error @validates_schema(pass_original=True) def check_unknown_fields(self, data, original_data, **kwargs): @@ -578,8 +575,7 @@ def validate_to(self, value): try: validate_phone_number(value, international=True) except InvalidPhoneError as error: - error_message = remap_phone_number_validation_messages(str(error)) - raise ValidationError(f"Invalid phone number: {error_message}") from error + raise ValidationError(f"Invalid phone number: {error.get_legacy_v2_api_error_message()}") from error @post_load def format_phone_number(self, item, **kwargs):