From dc0ec364e7a250db8811108953338ffcdc0baf1e Mon Sep 17 00:00:00 2001 From: vedantsahai18 Date: Fri, 20 Dec 2024 15:25:52 -0500 Subject: [PATCH] wip: initial set of exceptions added --- .../agents_api/queries/agents/create_agent.py | 58 +++++++++---------- .../queries/agents/create_or_update_agent.py | 37 +++++++++--- .../agents_api/queries/agents/delete_agent.py | 39 +++++++++---- .../agents_api/queries/agents/get_agent.py | 28 +++++---- .../agents_api/queries/agents/list_agents.py | 29 ++++++---- .../agents_api/queries/agents/patch_agent.py | 38 ++++++++---- .../agents_api/queries/agents/update_agent.py | 39 +++++++++---- .../queries/developers/create_developer.py | 4 +- .../queries/developers/patch_developer.py | 4 +- .../queries/developers/update_developer.py | 5 ++ .../agents_api/queries/files/create_file.py | 38 ++++++------ .../agents_api/queries/files/delete_file.py | 5 ++ .../agents_api/queries/files/get_file.py | 33 ++++++----- .../agents_api/queries/files/list_files.py | 13 ++++- .../sessions/create_or_update_session.py | 7 ++- .../queries/sessions/create_session.py | 7 ++- .../queries/sessions/delete_session.py | 2 +- .../queries/sessions/get_session.py | 2 +- .../queries/sessions/list_sessions.py | 18 +++--- .../queries/sessions/patch_session.py | 7 ++- .../queries/sessions/update_session.py | 7 ++- .../queries/users/create_or_update_user.py | 4 +- .../agents_api/queries/users/create_user.py | 6 +- .../agents_api/queries/users/delete_user.py | 2 +- .../agents_api/queries/users/get_user.py | 5 -- .../agents_api/queries/users/list_users.py | 5 -- .../agents_api/queries/users/patch_user.py | 4 +- .../agents_api/queries/users/update_user.py | 4 +- 28 files changed, 283 insertions(+), 167 deletions(-) diff --git a/agents-api/agents_api/queries/agents/create_agent.py b/agents-api/agents_api/queries/agents/create_agent.py index 76c96f46b..0b7a7d208 100644 --- a/agents-api/agents_api/queries/agents/create_agent.py +++ b/agents-api/agents_api/queries/agents/create_agent.py @@ -8,13 +8,16 @@ from beartype import beartype from sqlglot import parse_one from uuid_extensions import uuid7 - +import asyncpg +from fastapi import HTTPException from ...autogen.openapi_model import Agent, CreateAgentRequest from ...metrics.counters import increase_counter from ..utils import ( generate_canonical_name, pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -45,35 +48,30 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ), -# psycopg_errors.UniqueViolation: partialclass( -# HTTPException, -# status_code=409, -# detail="An agent with this canonical name already exists for this developer.", -# ), -# psycopg_errors.CheckViolation: partialclass( -# HTTPException, -# status_code=400, -# detail="The provided data violates one or more constraints. Please check the input values.", -# ), -# ValidationError: partialclass( -# HTTPException, -# status_code=400, -# detail="Input validation failed. Please check the provided data.", -# ), -# TypeError: partialclass( -# HTTPException, -# status_code=400, -# detail="A type mismatch occurred. Please review the input.", -# ), -# } -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="An agent with this canonical name already exists for this developer.", + ), + asyncpg.exceptions.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="The provided data violates one or more constraints. Please check the input values.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class( Agent, one=True, diff --git a/agents-api/agents_api/queries/agents/create_or_update_agent.py b/agents-api/agents_api/queries/agents/create_or_update_agent.py index ef3a0abe5..fd70e5f8b 100644 --- a/agents-api/agents_api/queries/agents/create_or_update_agent.py +++ b/agents-api/agents_api/queries/agents/create_or_update_agent.py @@ -7,6 +7,8 @@ from beartype import beartype from sqlglot import parse_one +from fastapi import HTTPException +import asyncpg from ...autogen.openapi_model import Agent, CreateOrUpdateAgentRequest from ...metrics.counters import increase_counter @@ -14,6 +16,8 @@ generate_canonical_name, pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -44,15 +48,30 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ) -# } -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="An agent with this canonical name already exists for this developer.", + ), + asyncpg.exceptions.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="The provided data violates one or more constraints. Please check the input values.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class( Agent, one=True, diff --git a/agents-api/agents_api/queries/agents/delete_agent.py b/agents-api/agents_api/queries/agents/delete_agent.py index c0ca3919f..64b3e392e 100644 --- a/agents-api/agents_api/queries/agents/delete_agent.py +++ b/agents-api/agents_api/queries/agents/delete_agent.py @@ -7,12 +7,16 @@ from beartype import beartype from sqlglot import parse_one +from fastapi import HTTPException +import asyncpg from ...autogen.openapi_model import ResourceDeletedResponse from ...common.utils.datetime import utcnow from ..utils import ( pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -59,17 +63,30 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ) -# } -# # TODO: Add more exceptions -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="An agent with this canonical name already exists for this developer.", + ), + asyncpg.exceptions.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="The provided data violates one or more constraints. Please check the input values.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class( ResourceDeletedResponse, one=True, diff --git a/agents-api/agents_api/queries/agents/get_agent.py b/agents-api/agents_api/queries/agents/get_agent.py index a731300fa..985937b0d 100644 --- a/agents-api/agents_api/queries/agents/get_agent.py +++ b/agents-api/agents_api/queries/agents/get_agent.py @@ -7,11 +7,15 @@ from beartype import beartype from sqlglot import parse_one +from fastapi import HTTPException +import asyncpg from ...autogen.openapi_model import Agent from ..utils import ( pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -35,16 +39,20 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ) -# } -# # TODO: Add more exceptions -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class(Agent, one=True, transform=lambda d: {"id": d["agent_id"], **d}) @pg_query @beartype diff --git a/agents-api/agents_api/queries/agents/list_agents.py b/agents-api/agents_api/queries/agents/list_agents.py index 87a0c942d..68ee3c73a 100644 --- a/agents-api/agents_api/queries/agents/list_agents.py +++ b/agents-api/agents_api/queries/agents/list_agents.py @@ -8,11 +8,13 @@ from beartype import beartype from fastapi import HTTPException - +import asyncpg from ...autogen.openapi_model import Agent from ..utils import ( pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -39,17 +41,20 @@ LIMIT $2 OFFSET $3; """ - -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ) -# } -# # TODO: Add more exceptions -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class(Agent, transform=lambda d: {"id": d["agent_id"], **d}) @pg_query @beartype diff --git a/agents-api/agents_api/queries/agents/patch_agent.py b/agents-api/agents_api/queries/agents/patch_agent.py index 69a5a6ca5..fef682858 100644 --- a/agents-api/agents_api/queries/agents/patch_agent.py +++ b/agents-api/agents_api/queries/agents/patch_agent.py @@ -7,12 +7,16 @@ from beartype import beartype from sqlglot import parse_one +from fastapi import HTTPException +import asyncpg from ...autogen.openapi_model import PatchAgentRequest, ResourceUpdatedResponse from ...metrics.counters import increase_counter from ..utils import ( pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -44,16 +48,30 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ) -# } -# # TODO: Add more exceptions -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="An agent with this canonical name already exists for this developer.", + ), + asyncpg.exceptions.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="The provided data violates one or more constraints. Please check the input values.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class( ResourceUpdatedResponse, one=True, diff --git a/agents-api/agents_api/queries/agents/update_agent.py b/agents-api/agents_api/queries/agents/update_agent.py index f28e28264..5e33fdddd 100644 --- a/agents-api/agents_api/queries/agents/update_agent.py +++ b/agents-api/agents_api/queries/agents/update_agent.py @@ -7,12 +7,15 @@ from beartype import beartype from sqlglot import parse_one - +from fastapi import HTTPException +import asyncpg from ...autogen.openapi_model import ResourceUpdatedResponse, UpdateAgentRequest from ...metrics.counters import increase_counter from ..utils import ( pg_query, wrap_in_class, + rewrap_exceptions, + partialclass, ) # Define the raw SQL query @@ -29,16 +32,30 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# { -# psycopg_errors.ForeignKeyViolation: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist.", -# ) -# } -# # TODO: Add more exceptions -# ) +@rewrap_exceptions( + { + asyncpg.exceptions.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer does not exist.", + ), + asyncpg.exceptions.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="An agent with this canonical name already exists for this developer.", + ), + asyncpg.exceptions.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="The provided data violates one or more constraints. Please check the input values.", + ), + asyncpg.exceptions.DataError: partialclass( + HTTPException, + status_code=400, + detail="Invalid data provided. Please check the input values.", + ), + } +) @wrap_in_class( ResourceUpdatedResponse, one=True, diff --git a/agents-api/agents_api/queries/developers/create_developer.py b/agents-api/agents_api/queries/developers/create_developer.py index bed6371c4..51011a63b 100644 --- a/agents-api/agents_api/queries/developers/create_developer.py +++ b/agents-api/agents_api/queries/developers/create_developer.py @@ -38,8 +38,8 @@ { asyncpg.UniqueViolationError: partialclass( HTTPException, - status_code=404, - detail="The specified developer does not exist.", + status_code=409, + detail="A developer with this email already exists.", ) } ) diff --git a/agents-api/agents_api/queries/developers/patch_developer.py b/agents-api/agents_api/queries/developers/patch_developer.py index af2ddb1f8..e14c8bbd0 100644 --- a/agents-api/agents_api/queries/developers/patch_developer.py +++ b/agents-api/agents_api/queries/developers/patch_developer.py @@ -26,8 +26,8 @@ { asyncpg.UniqueViolationError: partialclass( HTTPException, - status_code=404, - detail="The specified developer does not exist.", + status_code=409, + detail="A developer with this email already exists.", ) } ) diff --git a/agents-api/agents_api/queries/developers/update_developer.py b/agents-api/agents_api/queries/developers/update_developer.py index d41b333d5..659dcb111 100644 --- a/agents-api/agents_api/queries/developers/update_developer.py +++ b/agents-api/agents_api/queries/developers/update_developer.py @@ -28,6 +28,11 @@ HTTPException, status_code=404, detail="The specified developer does not exist.", + ), + asyncpg.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="A developer with this email already exists.", ) } ) diff --git a/agents-api/agents_api/queries/files/create_file.py b/agents-api/agents_api/queries/files/create_file.py index 48251fa5e..f2e35a6f4 100644 --- a/agents-api/agents_api/queries/files/create_file.py +++ b/agents-api/agents_api/queries/files/create_file.py @@ -60,25 +60,25 @@ # Add error handling decorator -# @rewrap_exceptions( -# { -# asyncpg.UniqueViolationError: partialclass( -# HTTPException, -# status_code=409, -# detail="A file with this name already exists for this developer", -# ), -# asyncpg.NoDataFoundError: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified owner does not exist", -# ), -# asyncpg.ForeignKeyViolationError: partialclass( -# HTTPException, -# status_code=404, -# detail="The specified developer does not exist", -# ), -# } -# ) +@rewrap_exceptions( + { + asyncpg.UniqueViolationError: partialclass( + HTTPException, + status_code=409, + detail="A file with this name already exists for this developer", + ), + asyncpg.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer or owner does not exist", + ), + asyncpg.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="File size must be positive and name must be between 1 and 255 characters", + ), + } +) @wrap_in_class( File, one=True, diff --git a/agents-api/agents_api/queries/files/delete_file.py b/agents-api/agents_api/queries/files/delete_file.py index 31cb43404..4cf0142ae 100644 --- a/agents-api/agents_api/queries/files/delete_file.py +++ b/agents-api/agents_api/queries/files/delete_file.py @@ -48,6 +48,11 @@ status_code=404, detail="File not found", ), + asyncpg.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer or owner does not exist", + ), } ) @wrap_in_class( diff --git a/agents-api/agents_api/queries/files/get_file.py b/agents-api/agents_api/queries/files/get_file.py index 5ccb08d86..882a93ab7 100644 --- a/agents-api/agents_api/queries/files/get_file.py +++ b/agents-api/agents_api/queries/files/get_file.py @@ -8,9 +8,12 @@ from beartype import beartype from sqlglot import parse_one +import asyncpg +from fastapi import HTTPException from ...autogen.openapi_model import File -from ..utils import pg_query, wrap_in_class +from ..utils import pg_query, wrap_in_class, rewrap_exceptions, partialclass, partialclass + # Define the raw SQL query file_query = parse_one(""" @@ -27,20 +30,20 @@ """).sql(pretty=True) -# @rewrap_exceptions( -# { -# asyncpg.NoDataFoundError: partialclass( -# HTTPException, -# status_code=404, -# detail="File not found", -# ), -# asyncpg.ForeignKeyViolationError: partialclass( -# HTTPException, -# status_code=404, -# detail="Developer not found", -# ), -# } -# ) +@rewrap_exceptions( + { + asyncpg.NoDataFoundError: partialclass( + HTTPException, + status_code=404, + detail="File not found", + ), + asyncpg.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer or owner does not exist", + ), + } +) @wrap_in_class( File, one=True, diff --git a/agents-api/agents_api/queries/files/list_files.py b/agents-api/agents_api/queries/files/list_files.py index 2f36def4f..7908bf37d 100644 --- a/agents-api/agents_api/queries/files/list_files.py +++ b/agents-api/agents_api/queries/files/list_files.py @@ -9,9 +9,10 @@ from beartype import beartype from fastapi import HTTPException from sqlglot import parse_one +import asyncpg from ...autogen.openapi_model import File -from ..utils import pg_query, wrap_in_class +from ..utils import pg_query, wrap_in_class, rewrap_exceptions, partialclass # Base query for listing files base_files_query = parse_one(""" @@ -21,7 +22,15 @@ WHERE f.developer_id = $1 """).sql(pretty=True) - +@rewrap_exceptions( + { + asyncpg.ForeignKeyViolationError: partialclass( + HTTPException, + status_code=404, + detail="The specified developer or owner does not exist", + ), + } +) @wrap_in_class( File, one=False, diff --git a/agents-api/agents_api/queries/sessions/create_or_update_session.py b/agents-api/agents_api/queries/sessions/create_or_update_session.py index 3c4dbf66e..b6c280b01 100644 --- a/agents-api/agents_api/queries/sessions/create_or_update_session.py +++ b/agents-api/agents_api/queries/sessions/create_or_update_session.py @@ -70,13 +70,18 @@ asyncpg.ForeignKeyViolationError: partialclass( HTTPException, status_code=404, - detail="The specified developer or participant does not exist.", + detail="The specified developer or session does not exist.", ), asyncpg.UniqueViolationError: partialclass( HTTPException, status_code=409, detail="A session with this ID already exists.", ), + asyncpg.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="Invalid session data provided.", + ), } ) @wrap_in_class( diff --git a/agents-api/agents_api/queries/sessions/create_session.py b/agents-api/agents_api/queries/sessions/create_session.py index 058462cf8..0bb967ce5 100644 --- a/agents-api/agents_api/queries/sessions/create_session.py +++ b/agents-api/agents_api/queries/sessions/create_session.py @@ -58,13 +58,18 @@ asyncpg.ForeignKeyViolationError: partialclass( HTTPException, status_code=404, - detail="The specified developer or participant does not exist.", + detail="The specified developer or session does not exist.", ), asyncpg.UniqueViolationError: partialclass( HTTPException, status_code=409, detail="A session with this ID already exists.", ), + asyncpg.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="Invalid session data provided.", + ), } ) @wrap_in_class( diff --git a/agents-api/agents_api/queries/sessions/delete_session.py b/agents-api/agents_api/queries/sessions/delete_session.py index 2e3234fe2..ff5317f58 100644 --- a/agents-api/agents_api/queries/sessions/delete_session.py +++ b/agents-api/agents_api/queries/sessions/delete_session.py @@ -30,7 +30,7 @@ asyncpg.ForeignKeyViolationError: partialclass( HTTPException, status_code=404, - detail="The specified developer does not exist.", + detail="The specified developer or session does not exist.", ), } ) diff --git a/agents-api/agents_api/queries/sessions/get_session.py b/agents-api/agents_api/queries/sessions/get_session.py index 1f704539e..cc12d0f88 100644 --- a/agents-api/agents_api/queries/sessions/get_session.py +++ b/agents-api/agents_api/queries/sessions/get_session.py @@ -51,7 +51,7 @@ asyncpg.ForeignKeyViolationError: partialclass( HTTPException, status_code=404, - detail="The specified developer does not exist.", + detail="The specified developer or session does not exist.", ), asyncpg.NoDataFoundError: partialclass( HTTPException, status_code=404, detail="Session not found" diff --git a/agents-api/agents_api/queries/sessions/list_sessions.py b/agents-api/agents_api/queries/sessions/list_sessions.py index 3aabaf32d..c113c0192 100644 --- a/agents-api/agents_api/queries/sessions/list_sessions.py +++ b/agents-api/agents_api/queries/sessions/list_sessions.py @@ -12,7 +12,7 @@ from ..utils import partialclass, pg_query, rewrap_exceptions, wrap_in_class # Define the raw SQL query -raw_query = """ +session_query = """ WITH session_participants AS ( SELECT sl.session_id, @@ -49,11 +49,6 @@ LIMIT $2 OFFSET $6; """ -# Parse and optimize the query -# query = parse_one(raw_query).sql(pretty=True) -query = raw_query - - @rewrap_exceptions( { asyncpg.ForeignKeyViolationError: partialclass( @@ -62,7 +57,14 @@ detail="The specified developer does not exist.", ), asyncpg.NoDataFoundError: partialclass( - HTTPException, status_code=404, detail="No sessions found" + HTTPException, + status_code=404, + detail="No sessions found", + ), + asyncpg.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="Invalid session data provided.", ), } ) @@ -94,7 +96,7 @@ async def list_sessions( tuple[str, list]: SQL query and parameters """ return ( - query, + session_query, [ developer_id, # $1 limit, # $2 diff --git a/agents-api/agents_api/queries/sessions/patch_session.py b/agents-api/agents_api/queries/sessions/patch_session.py index 7d526ae1a..d7533e124 100644 --- a/agents-api/agents_api/queries/sessions/patch_session.py +++ b/agents-api/agents_api/queries/sessions/patch_session.py @@ -37,13 +37,18 @@ asyncpg.ForeignKeyViolationError: partialclass( HTTPException, status_code=404, - detail="The specified developer or participant does not exist.", + detail="The specified developer or session does not exist.", ), asyncpg.NoDataFoundError: partialclass( HTTPException, status_code=404, detail="Session not found", ), + asyncpg.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="Invalid session data provided.", + ), } ) @wrap_in_class( diff --git a/agents-api/agents_api/queries/sessions/update_session.py b/agents-api/agents_api/queries/sessions/update_session.py index 7c58d10e6..e3f46c0af 100644 --- a/agents-api/agents_api/queries/sessions/update_session.py +++ b/agents-api/agents_api/queries/sessions/update_session.py @@ -33,13 +33,18 @@ asyncpg.ForeignKeyViolationError: partialclass( HTTPException, status_code=404, - detail="The specified developer or participant does not exist.", + detail="The specified developer or session does not exist.", ), asyncpg.NoDataFoundError: partialclass( HTTPException, status_code=404, detail="Session not found", ), + asyncpg.CheckViolationError: partialclass( + HTTPException, + status_code=400, + detail="Invalid session data provided.", + ), } ) @wrap_in_class( diff --git a/agents-api/agents_api/queries/users/create_or_update_user.py b/agents-api/agents_api/queries/users/create_or_update_user.py index 965ae4ce4..0a2936a9b 100644 --- a/agents-api/agents_api/queries/users/create_or_update_user.py +++ b/agents-api/agents_api/queries/users/create_or_update_user.py @@ -40,10 +40,10 @@ status_code=404, detail="The specified developer does not exist.", ), - asyncpg.UniqueViolationError: partialclass( # Add handling for potential race conditions + asyncpg.UniqueViolationError: partialclass( HTTPException, status_code=409, - detail="A user with this ID already exists.", + detail="A user with this ID already exists for the specified developer.", ), } ) diff --git a/agents-api/agents_api/queries/users/create_user.py b/agents-api/agents_api/queries/users/create_user.py index 8f35a646c..e246c7255 100644 --- a/agents-api/agents_api/queries/users/create_user.py +++ b/agents-api/agents_api/queries/users/create_user.py @@ -37,10 +37,10 @@ status_code=404, detail="The specified developer does not exist.", ), - asyncpg.NullValueNoIndicatorParameterError: partialclass( + asyncpg.UniqueViolationError: partialclass( HTTPException, - status_code=404, - detail="The specified developer does not exist.", + status_code=409, + detail="A user with this ID already exists for the specified developer.", ), } ) diff --git a/agents-api/agents_api/queries/users/delete_user.py b/agents-api/agents_api/queries/users/delete_user.py index ad5befd73..6b8497980 100644 --- a/agents-api/agents_api/queries/users/delete_user.py +++ b/agents-api/agents_api/queries/users/delete_user.py @@ -56,7 +56,7 @@ status_code=404, detail="The specified developer does not exist.", ), - asyncpg.UniqueViolationError: partialclass( + asyncpg.DataError: partialclass( HTTPException, status_code=404, detail="The specified user does not exist.", diff --git a/agents-api/agents_api/queries/users/get_user.py b/agents-api/agents_api/queries/users/get_user.py index 2b71f9192..07a840621 100644 --- a/agents-api/agents_api/queries/users/get_user.py +++ b/agents-api/agents_api/queries/users/get_user.py @@ -31,11 +31,6 @@ status_code=404, detail="The specified developer does not exist.", ), - asyncpg.UniqueViolationError: partialclass( - HTTPException, - status_code=404, - detail="The specified user does not exist.", - ), } ) @wrap_in_class(User, one=True) diff --git a/agents-api/agents_api/queries/users/list_users.py b/agents-api/agents_api/queries/users/list_users.py index 0f0818135..75fd62b4b 100644 --- a/agents-api/agents_api/queries/users/list_users.py +++ b/agents-api/agents_api/queries/users/list_users.py @@ -42,11 +42,6 @@ status_code=404, detail="The specified developer does not exist.", ), - asyncpg.UniqueViolationError: partialclass( - HTTPException, - status_code=404, - detail="The specified user does not exist.", - ), } ) @wrap_in_class(User) diff --git a/agents-api/agents_api/queries/users/patch_user.py b/agents-api/agents_api/queries/users/patch_user.py index c55ee31b7..fb2d8bfad 100644 --- a/agents-api/agents_api/queries/users/patch_user.py +++ b/agents-api/agents_api/queries/users/patch_user.py @@ -47,8 +47,8 @@ ), asyncpg.UniqueViolationError: partialclass( HTTPException, - status_code=404, - detail="The specified user does not exist.", + status_code=409, + detail="A user with this ID already exists for the specified developer.", ), } ) diff --git a/agents-api/agents_api/queries/users/update_user.py b/agents-api/agents_api/queries/users/update_user.py index 91572e15d..975dc57c7 100644 --- a/agents-api/agents_api/queries/users/update_user.py +++ b/agents-api/agents_api/queries/users/update_user.py @@ -31,8 +31,8 @@ ), asyncpg.UniqueViolationError: partialclass( HTTPException, - status_code=404, - detail="The specified user does not exist.", + status_code=409, + detail="A user with this ID already exists for the specified developer.", ), } )