mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-29 23:15:28 +08:00
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
from utils.util_log import test_log as log
|
|
|
|
|
|
class Error:
|
|
def __init__(self, error):
|
|
self.code = getattr(error, 'code', 99999)
|
|
self.message = getattr(error, 'message', str(error))
|
|
|
|
|
|
def api_request_catch():
|
|
def wrapper(func):
|
|
def inner_wrapper(*args, **kwargs):
|
|
try:
|
|
res = func(*args, **kwargs)
|
|
log.debug("(func_res) Response : %s " % str(res))
|
|
return res, True
|
|
except Exception as e:
|
|
# log.info("exception: %s", e)
|
|
log.error("[Partition API Exception]%s: %s" % (str(func), str(e)))
|
|
return Error(e), False
|
|
return inner_wrapper
|
|
return wrapper
|
|
|
|
|
|
@api_request_catch()
|
|
def api_request(_list, **kwargs):
|
|
if isinstance(_list, list):
|
|
func = _list[0]
|
|
if callable(func):
|
|
arg = []
|
|
if len(_list) > 1:
|
|
for a in _list[1:]:
|
|
arg.append(a)
|
|
log.debug("(func_req)[%s] Parameters ars arg: %s, kwargs: %s" % (str(func), str(arg), str(kwargs)))
|
|
return func(*arg, **kwargs)
|
|
return False, False
|