def call_api(api_fn, not_found=None):
try:
return api_fn()
except ApiException as e:
if e.status == 0:
raise e
elif e.status == 401:
handle_error("You are not authorized!")
elif e.status == 403:
handle_http_error(e.body, e.status)
elif e.status == 404 and not_found:
not_found()
else:
handle_http_error(e.body, e.status)
except LocationValueError as e:
handle_error("RiseML is not configured! Please run 'riseml user login' first!")
except HTTPError as e:
handle_error('Could not connect to API ({host}:{port}{url}) — {exc_type}'.format(
host=e.pool.host,
port=e.pool.port,
url=e.url,
exc_type=e.__class__.__name__
))
评论列表
文章目录