Skip to content

Commit

Permalink
chore(rename): rename to camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Mar 14, 2019
1 parent 975b907 commit 65e17d0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions ibm_cloud_sdk_core/api_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ class ApiException(Exception):
:param int code: The HTTP status code returned.
:param str message: A message describing the error.
:param dict info: A dictionary of additional information about the error.
:param response httpResponse: response
:param response http_response: response
"""
def __init__(self, code, message=None, info=None, httpResponse=None):
def __init__(self, code, message=None, info=None, http_response=None):
# Call the base class constructor with the parameters it needs
super(ApiException, self).__init__(message)
self.message = message
self.code = code
self.info = info
self.httpResponse = httpResponse
self.globalTransactionId = None
if httpResponse is not None:
self.globalTransactionId = httpResponse.headers.get('X-Global-Transaction-ID')
self.info = self.info if self.info else self._get_error_info(httpResponse)
self.message = self.message if self.message else self._get_error_message(httpResponse)
self.http_response = http_response
self.global_transaction_id = None
if http_response is not None:
self.global_transaction_id = http_response.headers.get('X-Global-Transaction-ID')
self.info = self.info if self.info else self._get_error_info(http_response)
self.message = self.message if self.message else self._get_error_message(http_response)

def __str__(self):
msg = 'Error: ' + str(self.message) + ', Code: ' + str(self.code)
if self.info is not None:
msg += ' , Information: ' + str(self.info)
if self.globalTransactionId is not None:
msg += ' , X-global-transaction-id: ' + str(self.globalTransactionId)
if self.global_transaction_id is not None:
msg += ' , X-global-transaction-id: ' + str(self.global_transaction_id)
return msg

def _get_error_info(self, response):
Expand Down
2 changes: 1 addition & 1 deletion ibm_cloud_sdk_core/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def request(self, method, url, accept_json=False, headers=None,
if response.status_code == 401:
error_message = 'Unauthorized: Access is denied due to ' \
'invalid credentials'
raise ApiException(response.status_code, error_message, httpResponse=response)
raise ApiException(response.status_code, error_message, http_response=response)

@staticmethod
def _convert_model(val, classname=None):
Expand Down
2 changes: 1 addition & 1 deletion ibm_cloud_sdk_core/iam_token_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def request(self, method, url, headers=None, params=None, data=None, **kwargs):
if 200 <= response.status_code <= 299:
return response.json()
else:
raise ApiException(response.status_code, httpResponse=response)
raise ApiException(response.status_code, http_response=response)

def get_token(self):
"""
Expand Down
12 changes: 6 additions & 6 deletions test/test_api_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_api_exception():
content_type='application/json')

mock_response = requests.get('https://test.com')
exception = ApiException(500, httpResponse=mock_response)
exception = ApiException(500, http_response=mock_response)
assert exception is not None
assert exception.message == 'sorry'

Expand All @@ -23,7 +23,7 @@ def test_api_exception():
body=json.dumps({'error_message': 'sorry again', 'msg': 'serious error'}),
content_type='application/json')
mock_response = requests.get('https://test-again.com')
exception = ApiException(500, httpResponse=mock_response)
exception = ApiException(500, http_response=mock_response)
assert exception.message == 'sorry again'

responses.add(responses.GET,
Expand All @@ -32,7 +32,7 @@ def test_api_exception():
body=json.dumps({'errorMessage': 'sorry once more', 'msg': 'serious error'}),
content_type='application/json')
mock_response = requests.get('https://test-once-more.com')
exception = ApiException(500, httpResponse=mock_response)
exception = ApiException(500, http_response=mock_response)
assert exception.message == 'sorry once more'

responses.add(responses.GET,
Expand All @@ -41,7 +41,7 @@ def test_api_exception():
body=json.dumps({'msg': 'serious error'}),
content_type='application/json')
mock_response = requests.get('https://test-msg.com')
exception = ApiException(500, httpResponse=mock_response)
exception = ApiException(500, http_response=mock_response)
assert exception.message == 'serious error'

responses.add(responses.GET,
Expand All @@ -50,14 +50,14 @@ def test_api_exception():
body=json.dumps({'statusInfo': 'not yet provisioned'}),
content_type='application/json')
mock_response = requests.get('https://test-status.com')
exception = ApiException(500, httpResponse=mock_response)
exception = ApiException(500, http_response=mock_response)
assert exception.message == 'not yet provisioned'

responses.add(responses.GET,
'https://test-for-text.com',
status=500,
body="plain text error")
mock_response = requests.get('https://test-for-text.com')
exception = ApiException(500, httpResponse=mock_response)
exception = ApiException(500, http_response=mock_response)
assert exception.message == 'plain text error'
assert exception.__str__() == 'Error: plain text error, Code: 500'

0 comments on commit 65e17d0

Please sign in to comment.