def buildFailureReply(errorNo, errorMsg=None): retObj = { "errorObj": { "errorNo": errorNo, "errorMsg": errorMsg or err_desc_ch.get(errorNo), "errorMsgEN": err_desc_en.get(errorNo), }, "data": None } return json.JSONEncoder().encode(retObj)
def handleTshService(s_name, env, arg): calllist = s_name.split('.') modulepath = calllist[:-1] funname = calllist[-1] db = dbmysql.mysqldb() DEBUG("Function name %s" % funname) try: service = __import__('modules'+'.'+'.'.join(modulepath), fromlist=['from modules import',]) except Exception as e: ERROR('Import module failed. [%s]' % s_name) ERROR('Import module failed. [%s]' % e) ERROR('Import module failed. [%s]' % traceback.format_exc()) del db, env return buildResult(SYSTEM_ERR) if hasattr(service, funname): funobj = getattr(service, funname) else: ERROR('There is no %s in %s' % (funname, modulepath)) del db, env, service return buildResult(SYSTEM_ERR) del service try: funret = funobj(db, env, arg) DEBUG(funret) except Exception as arg: ERROR('Error in %s: [%s]' % (s_name, arg)) ERROR('Import module failed. [%s]' % traceback.format_exc()) del funobj, db, env return buildResult(SYSTEM_ERR) del funobj, db, env RetCode = funret.get('RetCode') if type(RetCode) != int: ERROR('Wrong formatstr in function return data %s: [%s],ret[%s]' % (s_name, arg, funret)) return buildResult(SYSTEM_ERR) retObj = buildResult(RetCode, funret.get('RetObj')) retObj["RetMsg"] = err_desc_en.get(RetCode, '') return retObj
def buildReply(res): errorNo = res["RetCode"] retObj = { "errorObj": { "errorNo": errorNo, "errorMsg": res.get("RetMsg") or err_desc_ch.get(errorNo), "errorMsgEN": err_desc_en.get(errorNo), "errorLog": res["ErrorLog"] }, "data": res["RetObj"], "apiId": res.get("apiId") } if (errorNo == OCT_SUCCESS): if (res.get("session")): retObj["session"] = {"uuid": res["session"].get("id")} return json.JSONEncoder().encode(retObj)
def buildAsyncReply(res): data = res["RetObj"] errorNo = res["RetCode"] retObj = { "errorObj": { "errorNo": errorNo, "errorMsg": res.get("RetMsg") or err_desc_ch.get(errorNo), "errorMsgEN": err_desc_en.get(errorNo), }, "session": { "uuid": res["session"]["id"], }, "createTime": data["createTime"], "finishTime": data["finishTime"], "apiId": data["id"], "apiName": data["apiName"], "state": data["state"], "result": data["result"] } return json.JSONEncoder().encode(retObj)
def getErrorMsg(error): return err_desc_en.get(error) or ""