Skip to content

Commit

Permalink
Remove unused translation of new into old error messages
Browse files Browse the repository at this point in the history
That happens inside InvalidPhoneError class in notifications-utils
now.
  • Loading branch information
CrystalPea committed Jul 11, 2024
1 parent 636ae42 commit dda7c86
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
13 changes: 0 additions & 13 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
5 changes: 0 additions & 5 deletions app/notifications/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
10 changes: 3 additions & 7 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


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

0 comments on commit dda7c86

Please sign in to comment.