fix: full pagination + non-silent errors in PollingSonarrRetriever
Licence Check / Licence compatibility and copyright header verification (push) Successful in 43s
CI / Security audit (push) Successful in 59s
CI / Tests & coverage (push) Failing after 1m11s
Licence Check / Licence compatibility and copyright header verification (pull_request) Failing after 4s
CI / Tests & coverage (pull_request) Failing after 1m33s
CI / Security audit (pull_request) Successful in 1m39s

This commit is contained in:
2026-05-20 20:40:48 +01:00
parent 1f10414498
commit e772001c3f
+59 -21
View File
@@ -37,17 +37,35 @@ class PollingSonarrRetriever extends ArrRetriever {
* @returns {Promise<Object>} Queue object with records array
*/
async getQueue() {
try {
// Fetch with large page size to get all items (Sonarr has pagination)
const response = await axios.get(`${this.url}/api/v3/queue`, {
headers: { 'X-Api-Key': this.apiKey },
params: { includeSeries: true, includeEpisode: true, pageSize: 1000 }
});
return response.data;
} catch (error) {
logToFile(`[PollingSonarrRetriever] ${this.id} queue error: ${error.message}`);
return { records: [] };
}
const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
try {
const response = await axios.get(`${this.url}/api/v3/queue`, {
headers: { 'X-Api-Key': this.apiKey },
params: { includeSeries: true, includeEpisode: true, page, pageSize: 1000 }
});
responseData = response.data;
} catch (error) {
console.error(`Sonarr queue fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
throw error;
}
const records = responseData.records || (Array.isArray(responseData) ? responseData : []);
allRecords = allRecords.concat(records);
page++;
} while (
(responseData.records || (Array.isArray(responseData) ? responseData : [])).length === 1000 &&
page <= 50
);
return {
...responseData,
records: allRecords
};
}
/**
@@ -71,8 +89,14 @@ class PollingSonarrRetriever extends ArrRetriever {
startDate
} = options;
try {
const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
const params = {
page,
pageSize,
includeSeries,
includeEpisode
@@ -82,15 +106,29 @@ class PollingSonarrRetriever extends ArrRetriever {
if (sortDir) params.sortDir = sortDir;
if (startDate) params.startDate = startDate;
const response = await axios.get(`${this.url}/api/v3/history`, {
headers: { 'X-Api-Key': this.apiKey },
params
});
return response.data;
} catch (error) {
logToFile(`[PollingSonarrRetriever] ${this.id} history error: ${error.message}`);
return { records: [] };
}
try {
const response = await axios.get(`${this.url}/api/v3/history`, {
headers: { 'X-Api-Key': this.apiKey },
params
});
responseData = response.data;
} catch (error) {
console.error(`Sonarr history fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
throw error;
}
const records = responseData.records || (Array.isArray(responseData) ? responseData : []);
allRecords = allRecords.concat(records);
page++;
} while (
(responseData.records || (Array.isArray(responseData) ? responseData : [])).length === pageSize &&
page <= 50
);
return {
...responseData,
records: allRecords
};
}
}