diff --git a/networkapiclient/ApiGenericClient.py b/networkapiclient/ApiGenericClient.py index e7005c5..84f3ae0 100755 --- a/networkapiclient/ApiGenericClient.py +++ b/networkapiclient/ApiGenericClient.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. @@ -72,15 +73,12 @@ def get(self, uri): request.raise_for_status() - try: - return request.json() - except: - return request + return request.json() except HTTPError: - error = request + error = request.json() self.logger.error(error) - raise NetworkAPIClientError(str(error)) + raise NetworkAPIClientError(error.get('detail', '')) finally: self.logger.info('URI: %s', uri) if request: @@ -112,15 +110,16 @@ def post(self, uri, data=None, files=None): request.raise_for_status() - try: - return request.json() - except: - return request + return request.json() except HTTPError: - error = request + error = request.json() + self.logger.error(error) + raise NetworkAPIClientError(error.get('detail', '')) + except Exception: + error = request.json() self.logger.error(error) - raise NetworkAPIClientError(str(error)) + raise NetworkAPIClientError(error.get('detail', '')) finally: self.logger.info('URI: %s', uri) self.logger.info('Status Code: %s', @@ -150,15 +149,12 @@ def put(self, uri, data=None): request.raise_for_status() - try: - return request.json() - except: - return request + return request.json() except HTTPError: error = request.json() self.logger.error(error) - raise NetworkAPIClientError(str(error)) + raise NetworkAPIClientError(error.get('detail', '')) finally: self.logger.info('URI: %s', uri) self.logger.info('Status Code: %s', @@ -187,15 +183,12 @@ def delete(self, uri, data=None): request.raise_for_status() - try: - return request.json() - except: - return request + return request.json() except HTTPError: - error = request if request else "" + error = request.json() if request else "" self.logger.error(error) - raise NetworkAPIClientError(str(error)) + raise NetworkAPIClientError(error.get('detail', '')) finally: if request: self.logger.info('URI: %s', uri) diff --git a/networkapiclient/__init__.py b/networkapiclient/__init__.py index 7796cd1..bc8099b 100644 --- a/networkapiclient/__init__.py +++ b/networkapiclient/__init__.py @@ -16,5 +16,5 @@ MAJOR_VERSION = '0' MINOR_VERSION = '8' -PATCH_VERSION = '14' +PATCH_VERSION = '15' VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,))