fix(設定與 release 取得): 補 GITEA_REPOSITORY 格式驗證並讓 JSON 解析錯誤帶回傳內容
This commit is contained in:
+7
-3
@@ -15,9 +15,11 @@ const RELEASES_PER_PAGE = 10;
|
||||
* 進行授權請求,否則以匿名方式請求。
|
||||
* @param {{ info: (message: string) => void }} [options.logger] - 選用的記錄器,
|
||||
* 需提供 info() 方法以輸出進度訊息。
|
||||
* @returns {Promise<Array>} 解析為所有 release 物件合併後的陣列。
|
||||
* @throws {Error} 當網路請求失敗、response 非 2xx、回傳資料無法解析,
|
||||
* @returns {Promise<Array>} 解析為所有 release 物件合併後的陣列;首頁即無資料時回傳空陣列。
|
||||
* @throws {Error} 當網路請求失敗、response 非 2xx、回應本文讀取失敗、回傳資料無法解析,
|
||||
* 或回傳非陣列資料時拋出。
|
||||
* @remarks 依賴 Node.js 18+ 的全域 fetch;baseUrl 不含 query string,函式自行附加
|
||||
* `?limit=<RELEASES_PER_PAGE>&page=<n>` 逐頁請求,直到某頁空字串/`null`/不足一頁為止。
|
||||
*/
|
||||
async function fetchReleases(baseUrl, options = {}) {
|
||||
const { token, logger } = options;
|
||||
@@ -63,7 +65,9 @@ async function fetchReleases(baseUrl, options = {}) {
|
||||
try {
|
||||
pageJson = JSON.parse(text);
|
||||
} catch {
|
||||
throw new Error(`release API 回傳資料無法解析 (page=${page})`);
|
||||
// 附上截斷的回傳內容(至多 200 字元)以利定位回傳格式異常的確切原因
|
||||
const snippet = text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
||||
throw new Error(`release API 回傳資料無法解析 (page=${page}):${snippet}`);
|
||||
}
|
||||
|
||||
if (pageJson === null) {
|
||||
|
||||
Reference in New Issue
Block a user