@@ -34,7 +34,11 @@ async def _wait_task_and_stream_result(task_id: str, timeout_seconds: int, poll_
3434 raise HTTPException (status_code = 500 , detail = f"Task completed but no in-memory image found: { task_id } " )
3535
3636 if status == TaskStatus .FAILED .value :
37- raise HTTPException (status_code = 500 , detail = task_status .get ("error" , "Task failed" ))
37+ error_type = task_status .get ("error_type" , "" )
38+ error_detail = task_status .get ("error" , "Task failed" )
39+ if error_type == "ValueError" :
40+ raise HTTPException (status_code = 413 , detail = error_detail )
41+ raise HTTPException (status_code = 500 , detail = error_detail )
3842
3943 if status == TaskStatus .CANCELLED .value :
4044 raise HTTPException (status_code = 409 , detail = task_status .get ("error" , "Task cancelled" ))
@@ -108,6 +112,8 @@ async def create_image_task(message: ImageTaskRequest):
108112 save_result_path = message .save_result_path ,
109113 )
110114 except RuntimeError as e :
115+ if getattr (e , "original_error_type" , "" ) == "ValueError" :
116+ raise HTTPException (status_code = 413 , detail = str (e ))
111117 raise HTTPException (status_code = 503 , detail = str (e ))
112118 except Exception as e :
113119 logger .error (f"Failed to create image task: { e } " )
@@ -168,6 +174,8 @@ async def create_image_task_sync(
168174 raise
169175
170176 except RuntimeError as e :
177+ if getattr (e , "original_error_type" , "" ) == "ValueError" :
178+ raise HTTPException (status_code = 413 , detail = str (e ))
171179 raise HTTPException (status_code = 503 , detail = str (e ))
172180 except HTTPException :
173181 raise
@@ -229,6 +237,8 @@ async def save_file_async(file: UploadFile, target_dir: Path) -> str:
229237 save_result_path = message .save_result_path ,
230238 )
231239 except RuntimeError as e :
240+ if getattr (e , "original_error_type" , "" ) == "ValueError" :
241+ raise HTTPException (status_code = 413 , detail = str (e ))
232242 raise HTTPException (status_code = 503 , detail = str (e ))
233243 except Exception as e :
234244 logger .error (f"Failed to create image form task: { e } " )
0 commit comments