Skip to content

Commit

Permalink
🥅 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
agn-7 committed Nov 9, 2023
1 parent 478cb05 commit f719f30
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ifsguid/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ async def get_all_message_in_interaction(
per_page: Optional[int] = None,
db: Session = Depends(get_db),
) -> List[schemas.Message]:
interaction = crud.get_interaction(db=db, id=interaction_id)

if not interaction:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Interaction not found"
)

return [
schemas.Message.model_validate(message)
for message in crud.get_messages(
Expand All @@ -96,15 +103,15 @@ async def get_all_message_in_interaction(
async def create_message(
interaction_id: UUID, message: schemas.MessageCreate, db: Session = Depends(get_db)
) -> schemas.Message:
interaction = schemas.Interaction.model_validate(
crud.get_interaction(db=db, id=interaction_id)
)
interaction = crud.get_interaction(db=db, id=interaction_id)

if not interaction:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Interaction not found"
)

interaction = schemas.Interaction.model_validate(interaction)

messages = []
if message.role == "human":
ai_content = modules.generate_ai_response(
Expand Down

0 comments on commit f719f30

Please sign in to comment.