update APIException
This commit is contained in:
@@ -294,7 +294,7 @@ async def test(file:UploadFile= File(...),app:str=None):
|
||||
# kintone = getfieldsfromkintone(app)
|
||||
# fields = analysefields(excel,kintone["properties"])
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
||||
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}")
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail=f"File {file.filename} is not an Excel file")
|
||||
|
||||
@@ -310,7 +310,7 @@ async def download(request:Request,key,c:config.KINTONE_ENV=Depends(getkintoneen
|
||||
r = httpx.get(url,headers=headers,params=params)
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
raise APIException('kintone:upload',request.url._url,f"Error occurred while download file.json: {str(e)}")
|
||||
raise APIException('kintone:upload',request.url._url,f"Error occurred while download file.json:",e)
|
||||
|
||||
@r.post("/upload")
|
||||
async def upload(request:Request,files:t.List[UploadFile] = File(...)):
|
||||
@@ -323,9 +323,9 @@ async def upload(request:Request,files:t.List[UploadFile] = File(...)):
|
||||
print(df)
|
||||
dataframes.append(df)
|
||||
except Exception as e:
|
||||
raise APIException('kintone:upload',request.url._url,f"Error occurred while uploading file {file.filename}: {str(e)}")
|
||||
raise APIException('kintone:upload',request.url._url,f"Error occurred while uploading file {file.filename}:",e)
|
||||
else:
|
||||
raise APIException('kintone:upload',request.url._url, detail=f"File {file.filename} is not an Excel file")
|
||||
raise APIException('kintone:upload',request.url._url, f"File {file.filename} is not an Excel file",e)
|
||||
|
||||
return {"files": [file.filename for file in files]}
|
||||
|
||||
@@ -348,7 +348,7 @@ async def jscss(request:Request,app:str,files:t.List[UploadFile] = File(...),env
|
||||
deoployappfromkintone(app,appjscs["revision"],env)
|
||||
return appjscs
|
||||
except Exception as e:
|
||||
raise APIException('kintone:updatejscss',request.url._url, detail=f"Error occurred while update js/css {file.filename} is not an Excel file")
|
||||
raise APIException('kintone:updatejscss',request.url._url, f"Error occurred while update js/css {file.filename} is not an Excel file",e)
|
||||
|
||||
@r.get("/app")
|
||||
async def app(request:Request,app:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||
@@ -359,7 +359,7 @@ async def app(request:Request,app:str,c:config.KINTONE_ENV=Depends(getkintoneenv
|
||||
r = httpx.get(url,headers=headers,params=params)
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
raise APIException('kintone:app',request.url._url, detail=f"Error occurred while get app({c.DOMAIN_NAM}->{app}) : {str(e)}")
|
||||
raise APIException('kintone:app',request.url._url, f"Error occurred while get app({c.DOMAIN_NAM}->{app}):",e)
|
||||
|
||||
@r.get("/allapps")
|
||||
async def allapps(request:Request,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||
@@ -369,21 +369,21 @@ async def allapps(request:Request,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||
r = httpx.get(url,headers=headers)
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
raise APIException('kintone:allapps',request.url._url, detail=f"Error occurred while get allapps({c.DOMAIN_NAM}) : {str(e)}")
|
||||
raise APIException('kintone:allapps',request.url._url, f"Error occurred while get allapps({c.DOMAIN_NAM}):",e)
|
||||
|
||||
@r.get("/appfields")
|
||||
async def appfields(request:Request,app:str,env = Depends(getkintoneenv)):
|
||||
try:
|
||||
return getfieldsfromkintone(app,env)
|
||||
except Exception as e:
|
||||
raise APIException('kintone:appfields',request.url._url, detail=f"Error occurred while get app fileds({env.DOMAIN_NAM}->{app}) : {str(e)}")
|
||||
raise APIException('kintone:appfields',request.url._url, f"Error occurred while get app fileds({env.DOMAIN_NAM}->{app}):",e)
|
||||
|
||||
@r.get("/appprocess")
|
||||
async def appprocess(request:Request,app:str,env = Depends(getkintoneenv)):
|
||||
try:
|
||||
return getprocessfromkintone(app,env)
|
||||
except Exception as e:
|
||||
raise APIException('kintone:appprocess',request.url._url, detail=f"Error occurred while get app process({env.DOMAIN_NAM}->{app}) : {str(e)}")
|
||||
raise APIException('kintone:appprocess',request.url._url, f"Error occurred while get app process({env.DOMAIN_NAM}->{app}):",e)
|
||||
|
||||
@r.get("/alljscss")
|
||||
async def alljscs(request:Request,app:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||
@@ -394,7 +394,7 @@ async def alljscs(request:Request,app:str,c:config.KINTONE_ENV=Depends(getkinton
|
||||
r = httpx.get(url,headers=headers,params=params)
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
raise APIException('kintone:alljscss',request.url._url, detail=f"Error occurred while get app js/css({c.DOMAIN_NAM}->{app}) : {str(e)}")
|
||||
raise APIException('kintone:alljscss',request.url._url, f"Error occurred while get app js/css({c.DOMAIN_NAM}->{app}):",e)
|
||||
|
||||
@r.post("/createapp",)
|
||||
async def createapp(request:Request,name:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||
@@ -410,7 +410,7 @@ async def createapp(request:Request,name:str,c:config.KINTONE_ENV=Depends(getkin
|
||||
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
||||
return r.json
|
||||
except Exception as e:
|
||||
raise APIException('kintone:createapp',request.url._url, detail=f"Error occurred while create app({c.DOMAIN_NAM}->{name}) : {str(e)}")
|
||||
raise APIException('kintone:createapp',request.url._url, f"Error occurred while create app({c.DOMAIN_NAM}->{name}):",e)
|
||||
|
||||
property=["label","code","type","required","defaultValue","options"]
|
||||
|
||||
@@ -442,9 +442,9 @@ async def createappfromexcel(request:Request,files:t.List[UploadFile] = File(...
|
||||
result["revision"] = app["revision"]
|
||||
deoployappfromkintone(result["app"],result["revision"],env)
|
||||
except Exception as e:
|
||||
raise APIException('kintone:createappfromexcel',request.url._url, detail=f"Error occurred while parsing file ({env.DOMAIN_NAM}->{file.filename}) : {str(e)}")
|
||||
raise APIException('kintone:createappfromexcel',request.url._url, f"Error occurred while parsing file ({env.DOMAIN_NAM}->{file.filename}):",e)
|
||||
else:
|
||||
raise APIException('kintone:createappfromexcel',request.url._url, detail=f"File {file.filename} is not an Excel file")
|
||||
raise APIException('kintone:createappfromexcel',request.url._url, f"File {file.filename} is not an Excel file",e)
|
||||
return result
|
||||
|
||||
|
||||
@@ -493,9 +493,9 @@ async def updateappfromexcel(request:Request,app:str,files:t.List[UploadFile] =
|
||||
if deploy:
|
||||
result = deoployappfromkintone(app,revision,env)
|
||||
except Exception as e:
|
||||
raise APIException('kintone:updateappfromexcel',request.url._url, detail=f"Error occurred while parsing file ({env.DOMAIN_NAM}->{file.filename}) : {str(e)}")
|
||||
raise APIException('kintone:updateappfromexcel',request.url._url, f"Error occurred while parsing file ({env.DOMAIN_NAM}->{file.filename}):",e)
|
||||
else:
|
||||
raise APIException('kintone:updateappfromexcel',request.url._url, detail=f"File {file.filename} is not an Excel file")
|
||||
raise APIException('kintone:updateappfromexcel',request.url._url, f"File {file.filename} is not an Excel file",e)
|
||||
return result
|
||||
|
||||
@r.post("/updateprocessfromexcel",)
|
||||
@@ -530,7 +530,7 @@ async def updateprocessfromexcel(request:Request,app:str,env = Depends(getkinton
|
||||
if deploy:
|
||||
result = deoployappfromkintone(app,revision,env)
|
||||
except Exception as e:
|
||||
raise APIException('kintone:updateprocessfromexcel',request.url._url, detail=f"Error occurred while update process ({env.DOMAIN_NAM}->{app}) : {str(e)}")
|
||||
raise APIException('kintone:updateprocessfromexcel',request.url._url, f"Error occurred while update process ({env.DOMAIN_NAM}->{app}):",e)
|
||||
|
||||
return result
|
||||
|
||||
@@ -551,4 +551,4 @@ async def createjstokintone(request:Request,app:str,env:config.KINTONE_ENV = Dep
|
||||
deoployappfromkintone(app,appjscs["revision"],env)
|
||||
return appjscs
|
||||
except Exception as e:
|
||||
raise APIException('kintone:createjstokintone',request.url._url, detail=f"Error occurred while create js ({env.DOMAIN_NAM}->{app}) : {str(e)}")
|
||||
raise APIException('kintone:createjstokintone',request.url._url, f"Error occurred while create js ({env.DOMAIN_NAM}->{app}):",e)
|
||||
|
||||
@@ -23,7 +23,7 @@ async def appsetting_details(
|
||||
app = get_appsetting(db, id)
|
||||
return app
|
||||
except Exception as e:
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while get app setting: {str(e)}")
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while get app setting:",e)
|
||||
|
||||
@r.post("/appsettings", response_model=App, response_model_exclude_none=True)
|
||||
async def appsetting_create(
|
||||
@@ -34,7 +34,7 @@ async def appsetting_create(
|
||||
try:
|
||||
return create_appsetting(db, app)
|
||||
except Exception as e:
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while get create app setting: {str(e)}")
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while get create app setting:",e)
|
||||
|
||||
|
||||
@r.put(
|
||||
@@ -49,7 +49,7 @@ async def appsetting_edit(
|
||||
try:
|
||||
return edit_appsetting(db, id, app)
|
||||
except Exception as e:
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while edit app setting: {str(e)}")
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while edit app setting:",e)
|
||||
|
||||
|
||||
@r.delete(
|
||||
@@ -63,7 +63,7 @@ async def appsettings_delete(
|
||||
try:
|
||||
return delete_appsetting(db, id)
|
||||
except Exception as e:
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while delete app setting: {str(e)}")
|
||||
raise APIException('platform:appsettings',request.url._url,f"Error occurred while delete app setting:",e)
|
||||
|
||||
|
||||
@r.get(
|
||||
@@ -80,7 +80,7 @@ async def kintone_data(
|
||||
kintone = get_kintones(db, type)
|
||||
return kintone
|
||||
except Exception as e:
|
||||
raise APIException('platform:kintone',request.url._url,f"Error occurred while get kintone env: {str(e)}")
|
||||
raise APIException('platform:kintone',request.url._url,f"Error occurred while get kintone env:",e)
|
||||
|
||||
@r.get(
|
||||
"/actions",
|
||||
@@ -96,7 +96,7 @@ async def action_data(
|
||||
actions = get_actions(db)
|
||||
return actions
|
||||
except Exception as e:
|
||||
raise APIException('platform:actions',request.url._url,f"Error occurred while get actions: {str(e)}")
|
||||
raise APIException('platform:actions',request.url._url,f"Error occurred while get actions:",e)
|
||||
|
||||
@r.get(
|
||||
"/flow/{flowid}",
|
||||
@@ -112,7 +112,7 @@ async def flow_details(
|
||||
app = get_flow(db, flowid)
|
||||
return app
|
||||
except Exception as e:
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while get flow by flowid: {str(e)}")
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while get flow by flowid:",e)
|
||||
|
||||
|
||||
@r.get(
|
||||
@@ -132,7 +132,7 @@ async def flow_list(
|
||||
flows = get_flows_by_app(db, domain.id, appid)
|
||||
return flows
|
||||
except Exception as e:
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while get flow by appid: {str(e)}")
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while get flow by appid:",e)
|
||||
|
||||
|
||||
@r.post("/flow", response_model=Flow, response_model_exclude_none=True)
|
||||
@@ -146,7 +146,7 @@ async def flow_create(
|
||||
domain = get_activedomain(db, user.id)
|
||||
return create_flow(db, domain.id, flow)
|
||||
except Exception as e:
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while create flow: {str(e)}")
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while create flow:",e)
|
||||
|
||||
|
||||
@r.put(
|
||||
@@ -160,7 +160,7 @@ async def flow_edit(
|
||||
try:
|
||||
return edit_flow(db, flow)
|
||||
except Exception as e:
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while edit flow: {str(e)}")
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while edit flow:",e)
|
||||
|
||||
|
||||
@r.delete(
|
||||
@@ -174,7 +174,7 @@ async def flow_delete(
|
||||
try:
|
||||
return delete_flow(db, flowid)
|
||||
except Exception as e:
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while delete flow: {str(e)}")
|
||||
raise APIException('platform:flow',request.url._url,f"Error occurred while delete flow:",e)
|
||||
|
||||
@r.get(
|
||||
"/domains/{tenantid}",
|
||||
@@ -190,7 +190,7 @@ async def domain_details(
|
||||
domains = get_domains(db,tenantid)
|
||||
return domains
|
||||
except Exception as e:
|
||||
raise APIException('platform:domains',request.url._url,f"Error occurred while get domains: {str(e)}")
|
||||
raise APIException('platform:domains',request.url._url,f"Error occurred while get domains:",e)
|
||||
|
||||
@r.post("/domain", response_model=Domain, response_model_exclude_none=True)
|
||||
async def domain_create(
|
||||
@@ -201,7 +201,7 @@ async def domain_create(
|
||||
try:
|
||||
return create_domain(db, domain)
|
||||
except Exception as e:
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while create domain: {str(e)}")
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while create domain:",e)
|
||||
|
||||
|
||||
@r.put(
|
||||
@@ -215,7 +215,7 @@ async def domain_edit(
|
||||
try:
|
||||
return edit_domain(db, domain)
|
||||
except Exception as e:
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while edit domain: {str(e)}")
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while edit domain:",e)
|
||||
|
||||
|
||||
@r.delete(
|
||||
@@ -229,7 +229,7 @@ async def domain_delete(
|
||||
try:
|
||||
return delete_domain(db,id)
|
||||
except Exception as e:
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while delete domain: {str(e)}")
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while delete domain:",e)
|
||||
|
||||
@r.get(
|
||||
"/domain",
|
||||
@@ -245,7 +245,7 @@ async def userdomain_details(
|
||||
domains = get_domain(db, user.id)
|
||||
return domains
|
||||
except Exception as e:
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while get user({user.id}) domain: {str(e)}")
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while get user({user.id}) domain:",e)
|
||||
|
||||
@r.post(
|
||||
"/domain/{userid}",
|
||||
@@ -261,7 +261,7 @@ async def create_userdomain(
|
||||
domain = add_userdomain(db, userid,domainids)
|
||||
return domain
|
||||
except Exception as e:
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while add user({userid}) domain: {str(e)}")
|
||||
raise APIException('platform:domain',request.url._url,f"Error occurred while add user({userid}) domain:",e)
|
||||
|
||||
@r.delete(
|
||||
"/domain/{domainid}/{userid}", response_model_exclude_none=True
|
||||
@@ -275,7 +275,7 @@ async def userdomain_delete(
|
||||
try:
|
||||
return delete_userdomain(db, userid,domainid)
|
||||
except Exception as e:
|
||||
raise APIException('platform:delete',request.url._url,f"Error occurred while delete user({userid}) domain: {str(e)}")
|
||||
raise APIException('platform:delete',request.url._url,f"Error occurred while delete user({userid}) domain:",e)
|
||||
|
||||
|
||||
@r.get(
|
||||
@@ -292,7 +292,7 @@ async def get_useractivedomain(
|
||||
domain = get_activedomain(db, user.id)
|
||||
return domain
|
||||
except Exception as e:
|
||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain: {str(e)}")
|
||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while get user({user.id}) activedomain:",e)
|
||||
|
||||
@r.put(
|
||||
"/activedomain/{domainid}",
|
||||
@@ -308,7 +308,7 @@ async def update_activeuserdomain(
|
||||
domain = active_userdomain(db, user.id,domainid)
|
||||
return domain
|
||||
except Exception as e:
|
||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while update user({user.id}) activedomain: {str(e)}")
|
||||
raise APIException('platform:activedomain',request.url._url,f"Error occurred while update user({user.id}) activedomain:",e)
|
||||
|
||||
@r.get(
|
||||
"/events",
|
||||
@@ -324,7 +324,7 @@ async def event_data(
|
||||
events = get_events(db)
|
||||
return events
|
||||
except Exception as e:
|
||||
raise APIException('platform:events',request.url._url,f"Error occurred while get events: {str(e)}")
|
||||
raise APIException('platform:events',request.url._url,f"Error occurred while get events:",e)
|
||||
|
||||
|
||||
@r.get(
|
||||
@@ -342,4 +342,4 @@ async def eventactions_data(
|
||||
actions = get_eventactions(db,eventid)
|
||||
return actions
|
||||
except Exception as e:
|
||||
raise APIException('platform:eventactions',request.url._url,f"Error occurred while get eventactions: {str(e)}")
|
||||
raise APIException('platform:eventactions',request.url._url,f"Error occurred while get eventactions:",e)
|
||||
@@ -1,10 +1,19 @@
|
||||
from fastapi import HTTPException, status
|
||||
from app.db.schemas import ErrorCreate
|
||||
from app.db.session import SessionLocal
|
||||
from app.db.crud import create_log
|
||||
|
||||
class APIException(Exception):
|
||||
|
||||
def __init__(self,location:str,title:str,content:str):
|
||||
def __init__(self,location:str,title:str,content:str,e:Exception):
|
||||
if(str(e) == ''):
|
||||
content += e.detail
|
||||
self.detail = e.detail
|
||||
self.status_code = e.status_code
|
||||
else:
|
||||
self.detail = str(e)
|
||||
content += str(e)
|
||||
self.status_code = 500
|
||||
if(len(content) > 5000):
|
||||
content =content[0:5000]
|
||||
self.error = ErrorCreate(location=location,title=title,content=content)
|
||||
|
||||
@@ -54,8 +54,8 @@ async def api_exception_handler(request: Request, exc: APIException):
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_in_executor(None,writedblog,exc)
|
||||
return JSONResponse(
|
||||
status_code=400,
|
||||
content={"detail": f"{exc.error.content}"},
|
||||
status_code=exc.status_code,
|
||||
content={"detail": f"{exc.detail}"},
|
||||
)
|
||||
|
||||
@app.get("/api/v1")
|
||||
|
||||
Reference in New Issue
Block a user