2
0
mirror of https://opendev.org/x/pyghmi synced 2025-10-26 17:05:30 +00:00

Provide better messages when redfish provides

This provides a more informative behavior in the clients.

Change-Id: I7cecc39c3928aac6ee2d9b86ed53159dcdf3dde5
This commit is contained in:
Jarrod Johnson
2019-05-01 11:45:16 -04:00
parent 5c2c5d797f
commit a55dacf1d8
2 changed files with 13 additions and 1 deletions

View File

@@ -29,6 +29,10 @@ class IpmiException(PyghmiException):
self.ipmicode = code
class RedfishError(PyghmiException):
pass
class UnrecognizedCertificate(Exception):
def __init__(self, text='', certdata=None):
super(UnrecognizedCertificate, self).__init__(text)

View File

@@ -312,7 +312,15 @@ class Command(object):
if 'If-Match' in wc.stdheaders:
del wc.stdheaders['If-Match']
if res[1] < 200 or res[1] >= 300:
raise exc.PyghmiException(res[0])
try:
info = json.loads(res[0])
errmsg = [
x['Message'] for x in info.get('error', {}).get(
'@Message.ExtendedInfo', {})]
errmsg = ','.join(errmsg)
raise exc.RedfishError(errmsg)
except (ValueError, KeyError):
raise exc.PyghmiException(res[0])
if payload is None and method is None:
self._urlcache[url] = {'contents': res[0],
'vintage': os.times()[4]}