Commit 92abc15ba3dbfb7f133b7725ec4cfafa778bd329

Authored by Goutte
1 parent 3d597f3f

Mistrust the API some more.

Showing 1 changed file with 10 additions and 6 deletions   Show diff stats
web/run.py
... ... @@ -197,6 +197,7 @@ def retrieve_data(orbiter, what, started_at, stopped_at):
197 197 log.info("Fetching remote gzip files list at '%s'." % url)
198 198 retries = 0
199 199 success = False
  200 + errors = []
200 201 remote_gzip_files = []
201 202 while not success and retries < 3:
202 203 try:
... ... @@ -205,18 +206,20 @@ def retrieve_data(orbiter, what, started_at, stopped_at):
205 206 if not remote_gzip_files:
206 207 raise Exception("Failed to fetch data at '%s'." % url)
207 208 if remote_gzip_files == 'NODATASET':
208   - raise Exception("No dataset at '%s'." % url)
  209 + raise Exception("API says there's no dataset at '%s'." % url)
  210 + if remote_gzip_files == 'ERROR':
  211 + raise Exception("API returned an error at '%s'." % url)
  212 + if remote_gzip_files == ['OUTOFTIME']:
  213 + raise Exception("API says it's out of time at '%s'." % url)
209 214 success = True
210 215 except Exception as e:
211 216 log.warn("Failed (%d/3) '%s' : %s" % (retries+1, url, e.message))
  217 + remote_gzip_files = []
  218 + errors.append(e)
212 219 finally:
213 220 retries += 1
214 221 if not remote_gzip_files:
215   - abort(400, "Failed to fetch data at '%s'." % url)
216   - if remote_gzip_files == 'NODATASET':
217   - abort(400, "No dataset at '%s'." % url)
218   - # if remote_gzip_files == ['OUTOFTIME']:
219   - # abort(400, "No data for time interval at '%s'." % url)
  222 + abort(400, "Failed to fetch data at '%s' : %s" % (url, errors))
220 223  
221 224 log.debug("Fetched remote gzip files list : %s." % str(remote_gzip_files))
222 225  
... ... @@ -352,6 +355,7 @@ def generate_csv_file_if_needed(target_config, started_at, stopped_at):
352 355 log.info("Generation of '%s' done." % filename)
353 356 except Exception as e:
354 357 if isfile(local_csv_file):
  358 + log.warn("Removing failed CSV '%s'..." % local_csv_file)
355 359 removefile(local_csv_file)
356 360 abort(500, "Failed creating CSV '%s' : %s" % (filename, e))
357 361  
... ...