From 37f1ec1bef69f7e9a2dd8f7d2055e8a89ab9904c Mon Sep 17 00:00:00 2001
From: "Benedikt von St. Vieth" <b.von.st.vieth@fz-juelich.de>
Date: Tue, 20 Dec 2016 14:51:08 +0100
Subject: [PATCH] Gracefully exit when depositor is not able to fetch
 communities (probably because b2share is down).

---
 depositor/b2share.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/depositor/b2share.py b/depositor/b2share.py
index b3351c8..366ef83 100644
--- a/depositor/b2share.py
+++ b/depositor/b2share.py
@@ -1,6 +1,6 @@
 """a b2share depositor."""
 from furl import furl
-
+from requests.exceptions import ConnectionError
 import json
 import logging
 import requests
@@ -88,8 +88,13 @@ class Depositor:
         communitynames = {}
         communityids = {}
         # verify=False is needed while using fsd-cloud9 with self signed cert
-        r = requests.get(self.b2shareurl + "communities/",
-                         params=self.url_params, verify=self.insecure_ssl)
+        try:
+            r = requests.get(self.b2shareurl + "communities/",
+                             params=self.url_params, verify=self.insecure_ssl)
+        except ConnectionError:
+            logging.error('B2SHARE at {} currently not available'.format(
+                self.b2shareurl))
+            exit(1)
         i = 0
         for community in r.json()['hits']['hits']:
             communitynames.update({i: community['name']})
-- 
GitLab