@@ -216,20 +216,16 @@ def read_kktix_ticket_user_profile(task_type: str) -> list[str]:
216216 rows = client .query (query ).result () # 等 query 完成
217217 # 將每一 row 的 task_type 放到 list
218218 data_list = [row [task_type ] for row in rows ]
219- except NotFound as e :
220- logging .error (f"找不到資料表: { e } " )
221- raise
222- except BadRequest as e :
223- logging .error (f"SQL 語法錯誤或欄位不存在: { e } " )
224- raise
225- except Forbidden as e :
226- logging .error (f"BigQuery 權限不足: { e } " )
227- raise
228- except GoogleAPICallError as e :
229- logging .error (f"BigQuery API 呼叫錯誤: { e } " )
230- raise
231- except Exception :
232- logging .exception ("未知錯誤" )
219+ except (NotFound , BadRequest , Forbidden , GoogleAPICallError ) as err :
220+ if isinstance (err , NotFound ):
221+ err_msg = "找不到資料表: "
222+ elif isinstance (err , BadRequest ):
223+ err_msg = "SQL 語法錯誤或欄位不存在: "
224+ elif isinstance (err , BadRequest ):
225+ err_msg = "BigQuery 權限不足: "
226+ elif isinstance (err , GoogleAPICallError ):
227+ err_msg = "BigQuery API 呼叫錯誤: "
228+ logging .exception (err_msg )
233229 raise
234230 return data_list
235231
@@ -310,12 +306,12 @@ def process_table(
310306 result_json = []
311307 results_to_update .extend (result_json )
312308
313- except (GoogleAPICallError , DeadlineExceeded , ServiceUnavailable ) as e :
314- logging .error (f"批次 { index } API 呼叫錯誤: { e } " )
315- except requests .exceptions .RequestException as e :
316- logging .error (f"批次 { index } 網路請求錯誤: { e } " )
317- except ValueError as e :
318- logging .error (f"批次 { index } 資料格式錯誤: { e } " )
309+ except (GoogleAPICallError , DeadlineExceeded , ServiceUnavailable ):
310+ logging .exception (f"批次 { index } API 呼叫錯誤: " )
311+ except requests .exceptions .RequestException :
312+ logging .exception (f"批次 { index } 網路請求錯誤: " )
313+ except ValueError :
314+ logging .exception (f"批次 { index } 資料格式錯誤: " )
319315 except Exception :
320316 logging .exception (f"批次 { index } 未知錯誤" )
321317 # Add a small delay between batches to avoid hitting rate limits
0 commit comments