Michael Pasternak has uploaded a new change for review. Change subject: sdk: make request error being capable to handle any type of response ......................................................................
sdk: make request error being capable to handle any type of response Change-Id: Ia457618f7b86977c14bd6b1fb1397de484dd0371 Signed-off-by: Michael Pasternak <[email protected]> --- M src/ovirtsdk/infrastructure/errors.py 1 file changed, 33 insertions(+), 23 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/18/7318/1 diff --git a/src/ovirtsdk/infrastructure/errors.py b/src/ovirtsdk/infrastructure/errors.py index 860589a..78f130d 100644 --- a/src/ovirtsdk/infrastructure/errors.py +++ b/src/ovirtsdk/infrastructure/errors.py @@ -15,6 +15,7 @@ # from ovirtsdk.xml import params +import types class ERROR(Exception): def __init__(self, content): @@ -35,31 +36,40 @@ self.reason = None res = response.read() detail = '' + RESPONSE_FORMAT = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + RESPONSE_FAULT_BODY = '<fault>' - if res is not None and str(res) is not '' and str(res).find('Error report') != -1: - detail = res.lstrip() - elif res: - f_detail = params.parseString(res) - if isinstance(f_detail, params.Action) and f_detail.fault is not None: - #self.reason = f_detail.fault.reason - detail = f_detail.fault.detail.lstrip() + if res and res.startswith(RESPONSE_FORMAT) and res.find(RESPONSE_FAULT_BODY) != -1: + try: + f_detail = params.parseString(res) + except: + f_detail = '' + + if types.StringType != type(f_detail): + if isinstance(f_detail, params.Action) and f_detail.fault is not None: + #self.reason = f_detail.fault.reason + detail = f_detail.fault.detail.lstrip() + else: + #self.reason = response.reason + if f_detail is not None: + detail = f_detail.detail.lstrip() + + #engine returns can-do-action error messages with brackets + if detail.startswith('[') and detail.endswith(']'): + detail = detail[1:len(detail) - 1] + + #application server error + if detail.startswith('<html>'): + start = detail.find('<h1>') + end = detail.find('</h1>') + if start != -1 and end != -1: + detail = detail[start:end].replace('<h1>', '').replace('</h1>', '') + if detail and detail.endswith(' - '): + detail = detail[:len(detail) - 3] else: - #self.reason = response.reason - if f_detail is not None: - detail = f_detail.detail.lstrip() - - #engine returns can-do-action error messages with brackets - if detail.startswith('[') and detail.endswith(']'): - detail = detail[1:len(detail) - 1] - - #application server error - if detail.startswith('<html>'): - start = detail.find('<h1>') - end = detail.find('</h1>') - if start != -1 and end != -1: - detail = detail[start:end].replace('<h1>', '').replace('</h1>', '') - if detail and detail.endswith(' - '): - detail = detail[:len(detail) - 3] + detail = '\n' + res if res else '' + else: + detail = '\n' + res if res else '' self.detail = detail self.reason = response.reason -- To view, visit http://gerrit.ovirt.org/7318 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia457618f7b86977c14bd6b1fb1397de484dd0371 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
