'Calculate the reason for the error from the response content.'

def _get_reason(self):

    reason = self.resp.reason
    try:
        data = json.loads(self.content.decode('utf-8'))
        if isinstance(data, dict):
            reason = data['error']['message']
            if ('details' in data['error']):
                self.error_details = data['error']['details']
        elif (isinstance(data, list) and (len(data) > 0)):
            first_error = data[0]
            reason = first_error['error']['message']
            if ('details' in first_error['error']):
                self.error_details = first_error['error']['details']
    except (ValueError, KeyError, TypeError):
        pass
    if (reason is None):
        reason = ''
    return reason
