Repository: m0nhawk/grafana_api

Issue:
grafana_api does not pass errors to caller anymore
**Describe the bug**
```
in grafana_api.py, line 114:
            except Exception as error:
                print('Caught this error: ' + repr(error))
```
you are catching all exceptions you were throwing before - with the result, that all issues are hidden to the code that actually uses grafana_api. This is pretty much broken.

According to the commit, this is supposed to fix unit tests. If this fixes unit tests, they are also broken...

Expected would be that the errors are being raised.


Comments:

Patch:
diff --git a/Pipfile b/Pipfile
index f534687..2bc2f58 100644
--- a/Pipfile
+++ b/Pipfile
@@ -8,7 +8,7 @@ name = "grafana_api"
 [dev-packages]
 codecov = "~=2.0"
 coverage = "~=4.5"
-mock = {version = "*", markers = "python_version <= '2.7'"}
+mock = {version = "*",markers = "python_version <= '2.7'"}
 pylint = ">=1.9"
 requests-mock = "~=1.6"
 unittest-xml-reporting = "~=2.5"
diff --git a/grafana_api/grafana_api.py b/grafana_api/grafana_api.py
index 7c81439..e965768 100644
--- a/grafana_api/grafana_api.py
+++ b/grafana_api/grafana_api.py
@@ -94,25 +94,17 @@ class GrafanaAPI:
             r = runner(
                 __url, json=json, headers=headers, auth=self.auth, verify=self.verify
             )
-            try:
-
-                if 500 <= r.status_code < 600:
-                    raise GrafanaServerError(
-                        "Client Error {0}: {1}".format(r.status_code, r.json()['message'])
-                    )
-                elif r.status_code == 400:
-                    raise GrafanaBadInputError("Bad Input: `{0}`".format(r.text))
-                elif r.status_code == 401:
-                    raise GrafanaUnauthorizedError("Unauthorized")
-                elif 400 <= r.status_code < 500:
-                    raise GrafanaClientError(
-                        "Client Error {0}: {1}".format(r.status_code, r.text)
-                    )
-                return r.json()
-
-            except Exception as error:
-                print('Caught this error: ' + repr(error))
-
-
-
+            if 500 <= r.status_code < 600:
+                raise GrafanaServerError(
+                    "Client Error {0}: {1}".format(r.status_code, r.json()['message'])
+                )
+            elif r.status_code == 400:
+                raise GrafanaBadInputError("Bad Input: `{0}`".format(r.text))
+            elif r.status_code == 401:
+                raise GrafanaUnauthorizedError("Unauthorized")
+            elif 400 <= r.status_code < 500:
+                raise GrafanaClientError(
+                    "Client Error {0}: {1}".format(r.status_code, r.text)
+                )
+            return r.json()
         return __request_runnner


Test patch:
diff --git a/test/api/test_annotations.py b/test/api/test_annotations.py
index 3299748..3f278f7 100644
--- a/test/api/test_annotations.py
+++ b/test/api/test_annotations.py
@@ -99,29 +99,29 @@ class AnnotationsTestCase(unittest.TestCase):
     @requests_mock.Mocker()
     def test_delete_annotations_by_id_could_not_find(self, m):
         m.delete("http://localhost/api/annotations/None", json={"message": "Could not find annotation to update"},status_code=500)
-        response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
-        self.assertRaises(GrafanaServerError)
+        with self.assertRaises(GrafanaServerError):
+            response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
 
     @requests_mock.Mocker()
     def test_delete_annotations_by_id_forbidden(self, m):
         m.delete("http://localhost/api/annotations/None", json={"message": "Forbidden"},
                  status_code=403)
-        response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
-        self.assertRaises(GrafanaClientError)
+        with self.assertRaises(GrafanaClientError):
+            response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
 
     @requests_mock.Mocker()
     def test_delete_annotations_by_id_unauthorized(self, m):
         m.delete("http://localhost/api/annotations/None", json={"message": "Unauthorized"},
                      status_code=401)
-        response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
-        self.assertRaises(GrafanaUnauthorizedError)
+        with self.assertRaises(GrafanaUnauthorizedError):
+            response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
 
     @requests_mock.Mocker()
     def test_delete_annotations_by_id_bad_input(self, m):
         m.delete("http://localhost/api/annotations/None", json={"message": "Bad Input"},
                  status_code=400)
-        response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
-        self.assertRaises(GrafanaBadInputError)
+        with self.assertRaises(GrafanaBadInputError):
+            response = self.cli.annotations.delete_annotations_by_id(annotations_id=None)
 
 
     @requests_mock.Mocker()
diff --git a/test/api/test_folder.py b/test/api/test_folder.py
index 66b5f44..319eeaa 100644
--- a/test/api/test_folder.py
+++ b/test/api/test_folder.py
@@ -92,8 +92,8 @@ class FolderTestCase(unittest.TestCase):
                 "message": "Folder title cannot be empty"
             }, status_code=400
         )
-        folder = self.cli.folder.create_folder(title="Departmenet ABC")
-        self.assertRaises(GrafanaBadInputError)
+        with self.assertRaises(GrafanaBadInputError):
+            folder = self.cli.folder.create_folder(title="Departmenet ABC")
 
     @requests_mock.Mocker()
     def test_update_folder(self, m):
diff --git a/test/api/test_search.py b/test/api/test_search.py
index 134696b..cffa33c 100644
--- a/test/api/test_search.py
+++ b/test/api/test_search.py
@@ -46,5 +46,5 @@ class AnnotationsTestCase(unittest.TestCase):
             }, status_code=400
         )
 
-        result = self.cli.search.search_dashboards()
-        self.assertRaises(GrafanaBadInputError)
+        with self.assertRaises(GrafanaBadInputError):
+            result = self.cli.search.search_dashboards()