Skip to content

Commit

Permalink
Fix code scanning alert no. 10: Information exposure through an excep…
Browse files Browse the repository at this point in the history
…tion

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
bLopata and github-advanced-security[bot] authored Oct 15, 2024
1 parent f7e0cb1 commit 84ff08c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions api/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ def convo_turn():

return StreamingResponse(convo_turn())
except Exception as e:
# Log the error here if needed
# Log the error here
import logging
logging.error("An error occurred: %s", str(e))
if "rate limit" in str(e).lower():
return JSONResponse(
status_code=429,
content={"error": "rate_limit_exceeded", "message": str(e)}
content={"error": "rate_limit_exceeded", "message": "Rate limit exceeded. Please try again later."}
)
else:
return JSONResponse(
status_code=500,
content={"error": "internal_server_error", "message": str(e)}
content={"error": "internal_server_error", "message": "An internal server error has occurred."}
)


Expand All @@ -95,8 +97,10 @@ async def get_thought(conversation_id: str, message_id: str, user_id: str):
# In practice, there should only be one thought per message
return {"thought": thought.items[0].content if thought.items else None}
except Exception as e:
# Log the error here if needed
# Log the error here
import logging
logging.error("An error occurred: %s", str(e))
return JSONResponse(
status_code=500,
content={"error": "internal_server_error", "message": str(e)}
content={"error": "internal_server_error", "message": "An internal server error has occurred."}
)

0 comments on commit 84ff08c

Please sign in to comment.