Handle parse exception

This commit is contained in:
Michael Derynck 2022-09-21 12:36:52 -06:00
parent edac2e334f
commit b6faf425fd

View file

@ -4,6 +4,7 @@ from urllib.parse import urlparse
import phonenumbers
from django.apps import apps
from phonenumbers import NumberParseException
from python_http_client import UnauthorizedError
from sendgrid import SendGridAPIClient
from telegram import Bot
@ -126,8 +127,11 @@ class LiveSettingValidator:
@staticmethod
def _is_phone_number_valid(phone_number):
ph_num = phonenumbers.parse(phone_number)
return phonenumbers.is_valid_number(ph_num)
try:
ph_num = phonenumbers.parse(phone_number)
return phonenumbers.is_valid_number(ph_num)
except NumberParseException:
return False
@staticmethod
def _prettify_twilio_error(exc):