Skip to content

Commit

Permalink
exception of xlsx generation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Mar 10, 2024
1 parent 5a8b30c commit d590cd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/rcapi/api/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,15 @@ async def get_template(request : Request, response : Response,
_response.headers.update(custom_headers)
return _response
elif format=="xlsx":
file_path = template_service.get_template_xlsx(uuid,json_blueprint)
# Return the file using FileResponse
_response = FileResponse(file_path, media_type=format_supported[format]["mime"],
try:
file_path = template_service.get_template_xlsx(uuid,json_blueprint)
# Return the file using FileResponse
_response = FileResponse(file_path, media_type=format_supported[format]["mime"],
headers={"Content-Disposition": f'attachment; filename="{uuid}.{format}"'})
_response.headers.update(custom_headers)
return _response
_response.headers.update(custom_headers)
return _response
except Exception as err:
raise HTTPException(status_code=400, detail="The blueprint may not be complete. {}".format(err))
else:
raise HTTPException(status_code=400, detail="Format not supported")

Expand Down
11 changes: 7 additions & 4 deletions src/rcapi/services/template_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ def get_template_json(uuid):


def get_template_xlsx(uuid,json_blueprint):
file_path_xlsx = os.path.join(TEMPLATE_DIR, f"{uuid}.xlsx")
df_info,df_result,df_raw =bp.get_template_frame(json_blueprint)
bp.iom_format_2excel(file_path_xlsx,df_info,df_result,df_raw)
return file_path_xlsx
try:
file_path_xlsx = os.path.join(TEMPLATE_DIR, f"{uuid}.xlsx")
df_info,df_result,df_raw =bp.get_template_frame(json_blueprint)
bp.iom_format_2excel(file_path_xlsx,df_info,df_result,df_raw)
return file_path_xlsx
except Exception as err:
raise err

def get_nmparser_config(uuid,json_blueprint,force=True):
file_path = os.path.join(TEMPLATE_DIR, f"{uuid}.json.nmparser")
Expand Down

0 comments on commit d590cd8

Please sign in to comment.