Tailor message-too-long error message

depending on the notification type.

Up until now, only sms messages could get message-too-long error,
but now we also need to validate the size of email messages, so
the message content needs to be tailored to the notification type.
This commit is contained in:
Pea Tyczynska
2020-10-05 18:57:21 +01:00
parent d39379062d
commit 9708b09ba3
5 changed files with 42 additions and 18 deletions

View File

@@ -144,10 +144,19 @@ def check_if_service_can_send_to_number(service, number):
return international_phone_info
def check_content_char_count(template_with_content):
def check_message_is_not_too_long(template_with_content):
if template_with_content.is_message_too_long():
message = f"Text messages cannot be longer than {SMS_CHAR_COUNT_LIMIT} characters. " \
f"Your message is {template_with_content.content_count_without_prefix} characters"
message = "Your message is too long."
if template_with_content.template_type == SMS_TYPE:
message = (
f"Text messages cannot be longer than {SMS_CHAR_COUNT_LIMIT} characters. "
f"Your message is {template_with_content.content_count_without_prefix} characters long."
)
elif template_with_content.template_type == EMAIL_TYPE:
message = (
f"Emails cannot be longer than 7500000 bytes. "
f"Your message is {template_with_content.content_size_in_bytes} bytes."
)
raise BadRequestError(message=message)
@@ -173,7 +182,7 @@ def validate_template(template_id, personalisation, service, notification_type):
check_notification_content_is_not_empty(template_with_content)
check_content_char_count(template_with_content)
check_message_is_not_too_long(template_with_content)
return template, template_with_content