diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py index 225c9d64..73a9210f 100644 --- a/backend/apps/datasource/api/datasource.py +++ b/backend/apps/datasource/api/datasource.py @@ -565,7 +565,7 @@ async def parse_excel(file: UploadFile = File(..., description=f"{PLACEHOLDER_PR @router.post("/importToDb", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_import_to_db") -async def import_to_db(session: SessionDep, import_req: ImportRequest): +async def import_to_db(session: SessionDep, trans: Trans, import_req: ImportRequest): save_path = os.path.join(path, import_req.filePath) if not os.path.exists(save_path): raise HTTPException(400, "File not found") @@ -585,11 +585,14 @@ async def import_to_db(session: SessionDep, import_req: ImportRequest): for col in field_mapping.keys() } - if save_path.endswith(".csv"): - df = pd.read_csv(save_path, engine='c', dtype=dtype_dict) - sheet_name = "Sheet1" - else: - df = pd.read_excel(save_path, sheet_name=sheet_name, engine='calamine', dtype=dtype_dict) + try: + if save_path.endswith(".csv"): + df = pd.read_csv(save_path, engine='c', dtype=dtype_dict) + sheet_name = "Sheet1" + else: + df = pd.read_excel(save_path, sheet_name=sheet_name, engine='calamine', dtype=dtype_dict) + except Exception as e: + raise HTTPException(500, f"{trans('i18n_ds_upload_error')}: {str(e)}") conn = engine.raw_connection() cursor = conn.cursor() @@ -615,7 +618,7 @@ async def import_to_db(session: SessionDep, import_req: ImportRequest): "rows": len(df) }) except Exception as e: - raise HTTPException(400, f"Insert data failed for {table_name}: {str(e)}") + raise HTTPException(500, f"Insert data failed for {table_name}: {str(e)}") finally: cursor.close() conn.close() diff --git a/backend/locales/en.json b/backend/locales/en.json index b9638452..43db335b 100644 --- a/backend/locales/en.json +++ b/backend/locales/en.json @@ -51,6 +51,7 @@ "miss_default": "Default large language model has not been configured" }, "i18n_ds_invalid": "Datasource connection is invalid", + "i18n_ds_upload_error": "Upload Failed", "i18n_embedded": { "invalid_origin": "Domain name validation failed【{origin}】" }, diff --git a/backend/locales/ko-KR.json b/backend/locales/ko-KR.json index 77140ab6..bccbfdbb 100644 --- a/backend/locales/ko-KR.json +++ b/backend/locales/ko-KR.json @@ -51,6 +51,7 @@ "miss_default": "기본 대형 언어 모델이 구성되지 않았습니다" }, "i18n_ds_invalid": "데이터 소스 연결이 무효합니다", + "i18n_ds_upload_error": "파일 업로드 실패", "i18n_embedded": { "invalid_origin": "도메인 이름 검증 실패 【{origin}】" }, diff --git a/backend/locales/zh-CN.json b/backend/locales/zh-CN.json index 54bf9334..788e911e 100644 --- a/backend/locales/zh-CN.json +++ b/backend/locales/zh-CN.json @@ -51,6 +51,7 @@ "miss_default": "尚未配置默认大语言模型" }, "i18n_ds_invalid": "数据源连接无效", + "i18n_ds_upload_error": "上传文件失败", "i18n_embedded": { "invalid_origin": "域名校验失败【{origin}】" }, diff --git a/backend/locales/zh-TW.json b/backend/locales/zh-TW.json index 0bb90867..6b37aca9 100644 --- a/backend/locales/zh-TW.json +++ b/backend/locales/zh-TW.json @@ -51,6 +51,7 @@ "miss_default": "尚未配置默認大語言模型" }, "i18n_ds_invalid": "數據源連接無效", + "i18n_ds_upload_error": "上傳文件失敗", "i18n_embedded": { "invalid_origin": "網域校驗失敗【{origin}】" },