@@ -76,18 +76,41 @@ def process_json_data(golden_records):
76
76
if not unique_interaction_data .get ('auxIid' ):
77
77
unique_interaction_data ['auxIid' ] = interaction ['interaction' ]['uid' ]
78
78
print ("------------------------------------------------------" )
79
- print (golden_record )
79
+ print ("Old Golden ID--" + golden_record [ 'goldenRecord' ][ "uid" ] )
80
80
response = send_golden_record_to_api (golden_record )
81
- print (response .text )
81
+ if response :
82
+ print ("After Restore Golden ID--" + response .text )
82
83
83
84
def send_golden_record_to_api (golden_record_payload ):
84
85
get_expanded_golden_record_url = f'http://{ host } :{ port } /JeMPI/restoreGoldenRecord'
86
+ # Normalize date fields in the payload
87
+ if 'date' in golden_record_payload :
88
+ golden_record_payload ['date' ] = convert_datetime_format (golden_record_payload ['date' ])
89
+
85
90
payload = json .dumps (golden_record_payload )
86
91
headers = {
87
92
'Content-Type' : 'application/json'
88
93
}
89
- response = requests .post (get_expanded_golden_record_url , headers = headers , data = payload )
90
- return response
94
+
95
+ try :
96
+ response = requests .post (get_expanded_golden_record_url , headers = headers , data = payload )
97
+ response .raise_for_status ()
98
+ response_json = response .json ()
99
+ if 'errors' in response_json :
100
+ print (f"API error occurred: { response_json ['errors' ]} " )
101
+ return None
102
+ return response
103
+ except requests .exceptions .HTTPError as http_err :
104
+ print (f'HTTP error occurred: { http_err } ' )
105
+ except requests .exceptions .ConnectionError as conn_err :
106
+ print (f'Connection error occurred: { conn_err } ' )
107
+ except requests .exceptions .Timeout as timeout_err :
108
+ print (f'Timeout error occurred: { timeout_err } ' )
109
+ except requests .exceptions .RequestException as req_err :
110
+ print (f'An error occurred: { req_err } ' )
111
+ except json .JSONDecodeError as json_err :
112
+ print (f'JSON decode error: { json_err } ' )
113
+ return None
91
114
92
115
if __name__ == "__main__" :
93
116
# Check if a JSON file path is provided as an argument
0 commit comments