@@ -102,7 +102,7 @@ def submit_task_via_zapier(
102
102
else :
103
103
print (f"HTTP request failed with status code: { response .status_code } " )
104
104
print ("HTTP responce: " , response .text )
105
- return "Failed"
105
+ return "HTTP Request Failed"
106
106
107
107
def query_task_status (self , task_id : str ):
108
108
response = request (
@@ -115,21 +115,37 @@ def query_task_status(self, task_id: str):
115
115
},
116
116
)
117
117
if response .status_code != 200 :
118
- return "Not Found "
118
+ return "HTTP Request Failed. "
119
119
response_data = response .json ()
120
120
# Get "matched" from the response
121
121
matches = response_data .get ("matches" , None )
122
122
# The return is a list of dictionaries
123
123
# Verify if the list contains only one element
124
124
if matches is None :
125
125
print ("No task found with the given ID." )
126
- return "Failed"
126
+ return "Task searching Failed"
127
127
elif len (matches ) > 1 :
128
128
print ("Multiple tasks found with the given ID." )
129
- return "Failed"
129
+ return "Task searching Failed"
130
+
131
+ record = matches [0 ]
130
132
131
133
# Extract the status from the first dictionary
132
- status = matches [0 ].get ("status" )
134
+ status = record .get ("status" )
135
+
136
+ if status == "Failed validation" :
137
+ googledoc = record .get ("resultsFileUrl" )
138
+
139
+ # convert the preview URL to download URL
140
+ googledoc = convert_preview_to_download (googledoc )
141
+ res = get (googledoc )
142
+ res .raise_for_status ()
143
+ data = res .json ()
144
+ # get the "statusCode" and "message" from the data and print them out.
145
+ status_code = data .get ("statusCode" , "NA" )
146
+ message = data .get ("message" , "NA" )
147
+ print (f"Task validation failed with status code: { status_code } , message: { message } " )
148
+
133
149
return status
134
150
135
151
def fetch_results (self , task_id : str ):
@@ -283,7 +299,10 @@ def status(self) -> QuEraTaskStatusCode:
283
299
return QuEraTaskStatusCode .Unsubmitted
284
300
res = self ._http_handler .query_task_status (self ._task_id )
285
301
if res == "Failed" :
286
- raise ValueError ("Query task status failed." )
302
+ return QuEraTaskStatusCode .Failed
303
+ elif res == "Failed validation" :
304
+
305
+ return QuEraTaskStatusCode .Failed
287
306
elif res == "Submitted" :
288
307
return QuEraTaskStatusCode .Enqueued
289
308
# TODO: please add all possible status
0 commit comments