def callGData(service, function,
soft_errors=False, throw_errors=None, retry_errors=None,
**kwargs):
import gdata.apps.service
if throw_errors is None:
throw_errors = []
if retry_errors is None:
retry_errors = []
all_retry_errors = GDATA.NON_TERMINATING_ERRORS+retry_errors
method = getattr(service, function)
retries = 10
for n in range(1, retries+1):
try:
return method(**kwargs)
except gdata.apps.service.AppsForYourDomainException as e:
error_code, error_message = checkGDataError(e, service)
if (n != retries) and (error_code in all_retry_errors):
waitOnFailure(n, retries, error_code, error_message)
continue
if error_code in throw_errors:
if error_code in GDATA.ERROR_CODE_EXCEPTION_MAP:
raise GDATA.ERROR_CODE_EXCEPTION_MAP[error_code](error_message)
raise
if soft_errors:
stderrErrorMsg(u'{0} - {1}{2}'.format(error_code, error_message, [u'', u': Giving up.'][n > 1]))
return None
if error_code == GDATA.INSUFFICIENT_PERMISSIONS:
APIAccessDeniedExit()
systemErrorExit(GOOGLE_API_ERROR_RC, u'{0} - {1}'.format(error_code, error_message))
except oauth2client.client.AccessTokenRefreshError as e:
handleOAuthTokenError(str(e), GDATA.SERVICE_NOT_APPLICABLE in throw_errors)
raise GDATA.ERROR_CODE_EXCEPTION_MAP[GDATA.SERVICE_NOT_APPLICABLE](str(e))
except (http_client.ResponseNotReady, httplib2.SSLHandshakeError, socket.error) as e:
errMsg = u'Connection error: {0}'.format(str(e) or repr(e))
if n != retries:
waitOnFailure(n, retries, SOCKET_ERROR_RC, errMsg)
continue
if soft_errors:
writeStderr(convertUTF8(u'\n{0}{1} - Giving up.\n'.format(ERROR_PREFIX, errMsg)))
return None
systemErrorExit(SOCKET_ERROR_RC, errMsg)
except httplib2.ServerNotFoundError as e:
systemErrorExit(NETWORK_ERROR_RC, str(e))
评论列表
文章目录