Skip to content

Commit 24bc499

Browse files
committed
feat: updated error handling for sync jobs
1 parent 1e33f2c commit 24bc499

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

app/routers/sync_jobs.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from fastapi import Body, APIRouter, Depends, HTTPException, Response, status
33
from loguru import logger
44

5+
from app.error import DispatcherException, ErrorResponse, InternalException
6+
from app.middleware.error_handling import get_dispatcher_error_response
57
from app.schemas.enum import OutputFormatEnum, ProcessTypeEnum
68
from app.schemas.unit_job import (
79
BaseJobRequest,
@@ -23,6 +25,19 @@
2325
status_code=status.HTTP_201_CREATED,
2426
tags=["Unit Jobs"],
2527
summary="Create a new processing job",
28+
responses={
29+
InternalException.http_status: {
30+
"description": "Internal server error",
31+
"model": ErrorResponse,
32+
"content": {
33+
"application/json": {
34+
"example": get_dispatcher_error_response(
35+
InternalException(), "request-id"
36+
)
37+
}
38+
},
39+
},
40+
},
2641
)
2742
async def create_sync_job(
2843
payload: Annotated[
@@ -97,11 +112,10 @@ async def create_sync_job(
97112
"""Initiate a synchronous processing job with the provided data and return the result."""
98113
try:
99114
return await create_synchronous_job(token, payload)
100-
except HTTPException as e:
101-
raise e
115+
except DispatcherException as de:
116+
raise de
102117
except Exception as e:
103-
logger.exception(f"Error creating synchronous job: {e}")
104-
raise HTTPException(
105-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
106-
detail=f"An error occurred while creating the synchronous job: {e}",
118+
logger.error(f"Error creating synchronous job: {e}")
119+
raise InternalException(
120+
message="An error occurred while creating the synchronous job."
107121
)

0 commit comments

Comments
 (0)