Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/make responses uniform #51

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions py3cw/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,23 @@ def __make_request(self, http_method: str, path: str, params: any, payload: any,
error = {'error': True,
'msg': 'HTTP error occurred: {0}'.format(http_err),
'status_code': http_err.response.status_code if http_err.response else None}
return error, None
return error, {}

except Exception as generic_exc:
status_code = None
if 'response' in locals():
status_code = response.status_code
if not 'response_json' in locals():
return {
'error': True,
'msg': 'Other error occurred: {}'.format(generic_exc.args[0])
}, None
'msg': 'Other error occurred: {}'.format(generic_exc.args[0]),
'status_code': status_code
}, {}
return {'error': True, 'msg': 'Other error occurred: {} {} {}.'.format(
response_json.get('error'),
response_json.get('error_description'),
response_json.get('error_attributes')
)}, None
response_json.get('error_attributes')),
'status_code': status_code}, {}

@verify_request
def request(self, entity: str, action: str = '', action_id: str = None, action_sub_id: str = None,
Expand Down