Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrOertlin committed Mar 12, 2024
1 parent aba87de commit 4d50ba5
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions arnold/api/api_v1/endpoints/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from arnold.models.database.case.case import Case

router = APIRouter()
import logging

LOG = logging.getLogger(__name__)


@router.post(
Expand All @@ -19,20 +22,30 @@ def create_case(
adapter: ArnoldAdapter = Depends(get_arnold_adapter),
) -> JSONResponse:
"""Create a case document in the database."""
if read.case.get_case(case_id=case.id, adapter=adapter):
return JSONResponse(
status_code=status.HTTP_409_CONFLICT,
content="Case already in database.",
)
try:
existing_case = read.case.get_case(case_id=case.id, adapter=adapter)
if existing_case:
return JSONResponse(
status_code=status.HTTP_409_CONFLICT,
content={
"error": "Case already in database.",
"existing_case": existing_case,
},
)

create.create_case(case=case, adapter=adapter)
return JSONResponse(
status_code=status.HTTP_201_CREATED,
content=f"Case with {case.id} was created.",
)
except Exception as error:
# Log the error for debugging purposes
LOG.error(f"Error creating case: {error}", exc_info=True)

return JSONResponse(
status_code=status.HTTP_405_METHOD_NOT_ALLOWED, content=f"Error: {error}"
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={"error": f"Failed to create case. Details: {error}"},
)
return JSONResponse(
status_code=status.HTTP_201_CREATED, content=f"Case with {case.id} was created."
)


@router.get(
Expand Down

0 comments on commit 4d50ba5

Please sign in to comment.