From 92abc15ba3dbfb7f133b7725ec4cfafa778bd329 Mon Sep 17 00:00:00 2001 From: Goutte Date: Fri, 28 Jul 2017 21:00:43 +0200 Subject: [PATCH] Mistrust the API some more. --- web/run.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/web/run.py b/web/run.py index aaaccd6..92613d8 100755 --- a/web/run.py +++ b/web/run.py @@ -197,6 +197,7 @@ def retrieve_data(orbiter, what, started_at, stopped_at): log.info("Fetching remote gzip files list at '%s'." % url) retries = 0 success = False + errors = [] remote_gzip_files = [] while not success and retries < 3: try: @@ -205,18 +206,20 @@ def retrieve_data(orbiter, what, started_at, stopped_at): if not remote_gzip_files: raise Exception("Failed to fetch data at '%s'." % url) if remote_gzip_files == 'NODATASET': - raise Exception("No dataset at '%s'." % url) + raise Exception("API says there's no dataset at '%s'." % url) + if remote_gzip_files == 'ERROR': + raise Exception("API returned an error at '%s'." % url) + if remote_gzip_files == ['OUTOFTIME']: + raise Exception("API says it's out of time at '%s'." % url) success = True except Exception as e: log.warn("Failed (%d/3) '%s' : %s" % (retries+1, url, e.message)) + remote_gzip_files = [] + errors.append(e) finally: retries += 1 if not remote_gzip_files: - abort(400, "Failed to fetch data at '%s'." % url) - if remote_gzip_files == 'NODATASET': - abort(400, "No dataset at '%s'." % url) - # if remote_gzip_files == ['OUTOFTIME']: - # abort(400, "No data for time interval at '%s'." % url) + abort(400, "Failed to fetch data at '%s' : %s" % (url, errors)) log.debug("Fetched remote gzip files list : %s." % str(remote_gzip_files)) @@ -352,6 +355,7 @@ def generate_csv_file_if_needed(target_config, started_at, stopped_at): log.info("Generation of '%s' done." % filename) except Exception as e: if isfile(local_csv_file): + log.warn("Removing failed CSV '%s'..." % local_csv_file) removefile(local_csv_file) abort(500, "Failed creating CSV '%s' : %s" % (filename, e)) -- libgit2 0.21.2