Source code for exx.exceptions

# coding=utf-8


[docs]class ExxAPIException(Exception): """Exception class to handle general API Exceptions `code` values `message` format """
[docs] def __init__(self, response): self.code = '' self.message = 'Unknown Error' try: json_res = response.json() except ValueError: self.message = response.content else: if 'error' in json_res: self.message = json_res['error'] if 'code' in json_res: self.code = json_res['code'] self.message = json_res['message'] self.status_code = response.status_code self.response = response self.request = getattr(response, 'request', None)
def __str__(self): code_str = '' if self.code: code_str = ' {}'.format(self.code) return 'ExxAPIException{}: {}'.format(code_str, self.message)
[docs]class ExxRequestException(Exception):
[docs] def __init__(self, message): self.message = message
def __str__(self): return 'ExxRequestException: {}'.format(self.message)