mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Don’t 500 when searching with bad email address
In the future we might want to validate email addresses before attempting to search by them. But for a first pass we can just return no results when a user types in something that isn’t an email address or phone number. It definitely better than returning a 500.
This commit is contained in:
@@ -9,7 +9,8 @@ from flask import current_app
|
||||
from notifications_utils.recipients import (
|
||||
validate_and_format_phone_number,
|
||||
validate_and_format_email_address,
|
||||
InvalidPhoneError
|
||||
InvalidPhoneError,
|
||||
InvalidEmailError,
|
||||
)
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from sqlalchemy import (desc, func, or_, and_, asc)
|
||||
@@ -477,7 +478,10 @@ def dao_get_notifications_by_to_field(service_id, search_term, statuses=None):
|
||||
try:
|
||||
normalised = validate_and_format_phone_number(search_term)
|
||||
except InvalidPhoneError:
|
||||
normalised = validate_and_format_email_address(search_term)
|
||||
try:
|
||||
normalised = validate_and_format_email_address(search_term)
|
||||
except InvalidEmailError:
|
||||
normalised = search_term
|
||||
|
||||
filters = [
|
||||
Notification.service_id == service_id,
|
||||
|
||||
Reference in New Issue
Block a user