Skip to content

Commit

Permalink
feat: Add traceback to fastapi exception handler logs (#4099)
Browse files Browse the repository at this point in the history
Add traceback to fastapi exception handler logs
  • Loading branch information
cbornet authored Oct 11, 2024
1 parent d223ecc commit 8516f31
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 18 deletions.
9 changes: 0 additions & 9 deletions src/backend/base/langflow/api/v1/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ async def get_all(
)

except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc


Expand Down Expand Up @@ -277,13 +276,10 @@ async def simplified_run_flow(
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
if "not found" in str(exc):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
logger.exception(exc)
raise APIException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, exception=exc, flow=flow) from exc
except InvalidChatInputException as exc:
logger.exception(exc)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
except Exception as exc:
logger.exception(exc)
background_tasks.add_task(
telemetry_service.log_package_run,
RunPayload(
Expand Down Expand Up @@ -371,7 +367,6 @@ async def webhook_run_flow(
)
if "Flow ID is required" in str(exc) or "Request body is empty" in str(exc):
raise HTTPException(status_code=400, detail=str(exc)) from exc
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc


Expand Down Expand Up @@ -486,10 +481,8 @@ async def experimental_run_flow(
if f"Session {session_id} not found" in str(exc):
logger.exception(f"Session {session_id} not found")
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
logger.exception(exc)
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc)) from exc
except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc)) from exc


Expand Down Expand Up @@ -650,7 +643,6 @@ async def custom_component_update(

return component_node
except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=400, detail=str(exc)) from exc


Expand All @@ -662,5 +654,4 @@ def get_config():
settings_service: SettingsService = get_settings_service()
return settings_service.settings.model_dump()
except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc
1 change: 0 additions & 1 deletion src/backend/base/langflow/api/v1/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ async def delete_multiple_flows(
db.commit()
return {"deleted": len(flows_to_delete)}
except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc


Expand Down
2 changes: 0 additions & 2 deletions src/backend/base/langflow/api/v1/starter_projects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi import APIRouter, Depends, HTTPException
from loguru import logger

from langflow.graph.graph.schema import GraphDump
from langflow.services.auth.utils import get_current_active_user
Expand All @@ -19,5 +18,4 @@ def get_starter_projects(
try:
return get_starter_projects_dump()
except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc
1 change: 0 additions & 1 deletion src/backend/base/langflow/api/v1/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ def post_validate_prompt(prompt_request: ValidatePromptRequest):
frontend_node=prompt_request.frontend_node,
)
except Exception as e:
logger.exception(e)
raise HTTPException(status_code=500, detail=str(e)) from e
2 changes: 0 additions & 2 deletions src/backend/base/langflow/base/prompts/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def add_new_variables_to_template(input_variables, custom_fields, template, name
custom_fields[name].append(variable)

except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc


Expand All @@ -190,7 +189,6 @@ def remove_old_variables_from_template(old_custom_fields, input_variables, custo
template.pop(variable, None)

except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc


Expand Down
1 change: 0 additions & 1 deletion src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,6 @@ def from_payload(
except KeyError as exc:
logger.exception(exc)
if "nodes" not in payload and "edges" not in payload:
logger.exception(exc)
msg = f"Invalid payload. Expected keys 'nodes' and 'edges'. Found {list(payload.keys())}"
raise ValueError(msg) from exc

Expand Down
4 changes: 2 additions & 2 deletions src/backend/base/langflow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ async def flatten_query_string_lists(request: Request, call_next):
@app.exception_handler(Exception)
async def exception_handler(request: Request, exc: Exception):
if isinstance(exc, HTTPException):
logger.error(f"HTTPException: {exc.detail}")
logger.error(f"HTTPException: {exc}", exc_info=exc)
return JSONResponse(
status_code=exc.status_code,
content={"message": str(exc.detail)},
)
logger.error(f"unhandled error: {exc}")
logger.error(f"unhandled error: {exc}", exc_info=exc)
return JSONResponse(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
content={"message": str(exc)},
Expand Down

0 comments on commit 8516f31

Please sign in to comment.