From 650c9e5853ea57b985df1e9d97288a7d879a2e4f Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Thu, 13 Feb 2020 11:43:10 +0100 Subject: Implement general exception handling We trap the low level OBS api calls via a callback and check for success. If error returned, parse the OBS error response and raise an exception. --- obsapi/core.py | 88 ++++++++++++++++++++++++++++++++++--------------------- obsapi/httpapi.py | 2 -- 2 files changed, 54 insertions(+), 36 deletions(-) (limited to 'obsapi') diff --git a/obsapi/core.py b/obsapi/core.py index 209aab2..e91c408 100644 --- a/obsapi/core.py +++ b/obsapi/core.py @@ -17,6 +17,7 @@ SourceInfo = namedtuple('SourceInfo', 'package rev vrev srcmd5 verifymd5') Binary = namedtuple('Binary', 'filename size mtime') User = namedtuple('User', 'userid role') Group = namedtuple('Group', 'groupid role') +CallStatus = namedtuple('CallStatus', 'code, summary details') REGEX_NS = 'http://exslt.org/regular-expressions' DEFAULTAPIURL = 'https://api.opensuse.org' @@ -52,11 +53,59 @@ class ObsApi(object): def _api_callback(self, api_instance): self.lastapi = api_instance + print(self.response.text) + if not self.success: + self._raise_error() + + def _raise_error(self): + msg = self.status_message + raise Exception(msg) + + @property + def call_status(self): + + if not self.response.text.strip().startswith('