From a86928c0a7a23034fb6d4d50b7ffb64e6b2eb33d Mon Sep 17 00:00:00 2001
From: leufen1 <l.leufen@fz-juelich.de>
Date: Wed, 2 Dec 2020 15:32:22 +0100
Subject: [PATCH] join handles now bad request reponses, /close #224

---
 mlair/helpers/join.py               | 7 +++++--
 mlair/run_modules/pre_processing.py | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/mlair/helpers/join.py b/mlair/helpers/join.py
index b772a053..8a8ca0b8 100644
--- a/mlair/helpers/join.py
+++ b/mlair/helpers/join.py
@@ -70,7 +70,7 @@ def download_join(station_name: Union[str, List[str]], stat_var: dict, station_t
 
             # create data link
             opts = {'base': join_url_base, 'service': 'stats', 'id': vars_dict[var], 'statistics': stat_var[var],
-                    'sampling': sampling, 'capture': 0, 'min_data_length': 1460, 'format': 'json'}
+                    'sampling': sampling, 'capture': 0, 'format': 'json'}
 
             # load data
             data = get_data(opts, headers)
@@ -130,7 +130,10 @@ def get_data(opts: Dict, headers: Dict) -> Union[Dict, List]:
     """
     url = create_url(**opts)
     response = requests.get(url, headers=headers)
-    return response.json()
+    if response.status_code == 200:
+        return response.json()
+    else:
+        raise EmptyQueryResult(f"There was an error (STATUS {response.status_code}) for request {url}")
 
 
 def load_series_information(station_name: List[str], station_type: str_or_none, network_name: str_or_none,
diff --git a/mlair/run_modules/pre_processing.py b/mlair/run_modules/pre_processing.py
index 8be5870a..0238ad0e 100644
--- a/mlair/run_modules/pre_processing.py
+++ b/mlair/run_modules/pre_processing.py
@@ -333,7 +333,7 @@ def f_proc(data_handler, station, name_affix, store, **kwargs):
     try:
         res = data_handler.build(station, name_affix=name_affix, store_processed_data=store,
                                  **kwargs)
-    except (AttributeError, EmptyQueryResult, KeyError, requests.ConnectionError) as e:
+    except (AttributeError, EmptyQueryResult, KeyError, requests.ConnectionError, ValueError) as e:
         logging.info(f"remove station {station} because it raised an error: {e}")
         res = None
     return res, station
-- 
GitLab