Return INVALID_PARAM if phone number cannot be parsed

This commit is contained in:
David Baker 2024-08-19 15:18:38 +01:00
parent 93bd033fbe
commit 80dc51171f

View file

@ -21,7 +21,7 @@
import phonenumbers
from synapse.api.errors import SynapseError
from synapse.api.errors import SynapseError, Codes
def phone_number_to_msisdn(country: str, number: str) -> str:
@ -45,7 +45,7 @@ def phone_number_to_msisdn(country: str, number: str) -> str:
try:
phoneNumber = phonenumbers.parse(number, country)
except phonenumbers.NumberParseException:
raise SynapseError(400, "Unable to parse phone number")
raise SynapseError(400, "Unable to parse phone number", Codes.INVALID_PARAM)
return phonenumbers.format_number(phoneNumber, phonenumbers.PhoneNumberFormat.E164)[
1:
]