'Handle API call result'

def handleResult(self, result):

    if ('code' not in result):
        raise Exception('API    response    has    no    code')
    if ('message' not in result):
        raise Exception('API    response    has    no    message')
    if ('data' not in result):
        result['data'] = None
    if (result['code'] == self.CODE_OK):
        return result['data']
    elif ((result['code'] == self.CODE_INVALID_PARAMETERS) or (result['code'] == self.CODE_INVALID_API_KEY)):
        raise ValueError(result['message'])
    elif (result['code'] == self.CODE_INTERNAL_ERROR):
        raise Exception(result['message'])
    elif (result['code'] == self.CODE_INVALID_FUNCTION):
        raise Exception(result['message'])
    else:
        raise Exception('An    unexpected    error    occurred    whilst    handling    the    response')
