mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 10:42:25 -05:00
This morning we raise a ParseError for a bad date format for the DateReceived attribute on the /notifications/receive/mmg request.
This PR tries to parse the date, if that throws an error return now as the datereceived. This will at least allow the message to be persisted. Typically the DateReceived, provider_date, and the created_at date in the inbound_sms table are within a second of each other.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime
|
||||
from urllib.parse import unquote
|
||||
|
||||
import iso8601
|
||||
@@ -115,9 +116,12 @@ def format_mmg_datetime(date):
|
||||
We expect datetimes in format 2017-05-21+11%3A56%3A11 - ie, spaces replaced with pluses, and URI encoded
|
||||
and in UTC
|
||||
"""
|
||||
orig_date = format_mmg_message(date)
|
||||
parsed_datetime = iso8601.parse_date(orig_date).replace(tzinfo=None)
|
||||
return parsed_datetime
|
||||
try:
|
||||
orig_date = format_mmg_message(date)
|
||||
parsed_datetime = iso8601.parse_date(orig_date).replace(tzinfo=None)
|
||||
return parsed_datetime
|
||||
except iso8601.ParseError:
|
||||
return datetime.utcnow()
|
||||
|
||||
|
||||
def create_inbound_sms_object(service, content, from_number, provider_ref, date_received, provider_name):
|
||||
|
||||
Reference in New Issue
Block a user