Skip to content

Commit

Permalink
fix: Add exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Dec 27, 2024
1 parent ea37837 commit c5377b9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions agents-api/agents_api/queries/docs/get_doc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from uuid import UUID

import asyncpg
from fastapi import HTTPException
from beartype import beartype
from sqlglot import parse_one

from ...autogen.openapi_model import Doc
from ..utils import pg_query, wrap_in_class
from ..utils import pg_query, wrap_in_class, rewrap_exceptions, partialclass

# Update the query to use DISTINCT ON to prevent duplicates
doc_with_embedding_query = parse_one("""
doc_with_embedding_query = """
WITH doc_data AS (
SELECT
d.doc_id,
Expand Down Expand Up @@ -39,7 +40,7 @@
d.created_at
)
SELECT * FROM doc_data;
""").sql(pretty=True)
"""


def transform_get_doc(d: dict) -> dict:
Expand All @@ -57,7 +58,15 @@ def transform_get_doc(d: dict) -> dict:
}
return transformed


@rewrap_exceptions(
{
asyncpg.exceptions.ForeignKeyViolationError: partialclass(
HTTPException,
status_code=404,
detail="The specified doc does not exist.",
),
}
)
@wrap_in_class(
Doc,
one=True,
Expand Down

0 comments on commit c5377b9

Please sign in to comment.