fix: full pagination + non-silent errors in PollingSonarrRetriever #26

Merged
Gandalf merged 1 commits from fix-sonarr-retriever into develop-merge 2026-05-20 21:00:54 +01:00
+47 -9
View File
@@ -37,17 +37,35 @@ class PollingSonarrRetriever extends ArrRetriever {
* @returns {Promise<Object>} Queue object with records array * @returns {Promise<Object>} Queue object with records array
*/ */
async getQueue() { async getQueue() {
const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
try { try {
// Fetch with large page size to get all items (Sonarr has pagination)
const response = await axios.get(`${this.url}/api/v3/queue`, { const response = await axios.get(`${this.url}/api/v3/queue`, {
headers: { 'X-Api-Key': this.apiKey }, headers: { 'X-Api-Key': this.apiKey },
params: { includeSeries: true, includeEpisode: true, pageSize: 1000 } params: { includeSeries: true, includeEpisode: true, page, pageSize: 1000 }
}); });
return response.data; responseData = response.data;
} catch (error) { } catch (error) {
logToFile(`[PollingSonarrRetriever] ${this.id} queue error: ${error.message}`); console.error(`Sonarr queue fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
return { records: [] }; 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 startDate
} = options; } = options;
try { const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
const params = { const params = {
page,
pageSize, pageSize,
includeSeries, includeSeries,
includeEpisode includeEpisode
@@ -82,15 +106,29 @@ class PollingSonarrRetriever extends ArrRetriever {
if (sortDir) params.sortDir = sortDir; if (sortDir) params.sortDir = sortDir;
if (startDate) params.startDate = startDate; if (startDate) params.startDate = startDate;
try {
const response = await axios.get(`${this.url}/api/v3/history`, { const response = await axios.get(`${this.url}/api/v3/history`, {
headers: { 'X-Api-Key': this.apiKey }, headers: { 'X-Api-Key': this.apiKey },
params params
}); });
return response.data; responseData = response.data;
} catch (error) { } catch (error) {
logToFile(`[PollingSonarrRetriever] ${this.id} history error: ${error.message}`); console.error(`Sonarr history fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
return { records: [] }; 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
};
} }
} }