diff --git a/zuulclient/api/__init__.py b/zuulclient/api/__init__.py index 66833d5..d2f0f93 100644 --- a/zuulclient/api/__init__.py +++ b/zuulclient/api/__init__.py @@ -90,16 +90,28 @@ class ZuulRESTClient(object): def _check_request_status(self, req): try: req.raise_for_status() + msg = None except Exception as e: if req.status_code == 401: - raise ZuulRESTException( - 'Unauthorized - your token might be invalid or expired.') + msg = \ + 'Unauthorized - your token might be invalid or expired.' elif req.status_code == 403: - raise ZuulRESTException( - 'Insufficient privileges to perform the action.') + msg = \ + 'Insufficient privileges to perform the action.' else: - raise ZuulRESTException( - 'Unknown error code %s: "%s"' % (req.status_code, e)) + msg = \ + 'Unknown error code %s: "%s"' % (req.status_code, e) + + try: + doc = req.json() + msg = '%s: %s' % (doc['error'], doc['description']) + except Exception: + pass + # This is outside the above handler in order to suppress the + # original exception (this one will still have an appropriate + # traceback; we don't need both). + if msg: + raise ZuulRESTException(msg) def _check_scope(self, tenant): scope = self.info.get("tenant", None)