|
2 | 2 | from fastapi import Body, APIRouter, Depends, HTTPException, Response, status |
3 | 3 | from loguru import logger |
4 | 4 |
|
| 5 | +from app.error import DispatcherException, ErrorResponse, InternalException |
| 6 | +from app.middleware.error_handling import get_dispatcher_error_response |
5 | 7 | from app.schemas.enum import OutputFormatEnum, ProcessTypeEnum |
6 | 8 | from app.schemas.unit_job import ( |
7 | 9 | BaseJobRequest, |
|
23 | 25 | status_code=status.HTTP_201_CREATED, |
24 | 26 | tags=["Unit Jobs"], |
25 | 27 | 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 | + }, |
26 | 41 | ) |
27 | 42 | async def create_sync_job( |
28 | 43 | payload: Annotated[ |
@@ -97,11 +112,10 @@ async def create_sync_job( |
97 | 112 | """Initiate a synchronous processing job with the provided data and return the result.""" |
98 | 113 | try: |
99 | 114 | return await create_synchronous_job(token, payload) |
100 | | - except HTTPException as e: |
101 | | - raise e |
| 115 | + except DispatcherException as de: |
| 116 | + raise de |
102 | 117 | 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." |
107 | 121 | ) |
0 commit comments