From 86758cce19d63a6520db50f88359cb85547191ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 5 Aug 2016 11:13:26 +0200 Subject: [PATCH] Properly handle errors while fetching the types. Fix #53 --- pymisp/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index b92cdb3..9389bcc 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -115,7 +115,11 @@ class PyMISP(object): raise PyMISPError('Unable to connect to MISP ({}). Please make sure the API key and the URL are correct (http/https is required): {}'.format(self.root_url, e)) session = self.__prepare_session(out_type) - self.describe_types = session.get(urljoin(self.root_url, 'attributes/describeTypes.json')).json() + response = session.get(urljoin(self.root_url, 'attributes/describeTypes.json')) + self.describe_types = self._check_response(response) + if self.describe_types.get('error'): + for e in self.describe_types.get('error'): + raise PyMISPError('Failed: {}'.format(e)) self.categories = self.describe_types['result']['categories'] self.types = self.describe_types['result']['types']