Further refine TVDB API show details implementation with better error handling
This commit is contained in:
parent
421e223a6a
commit
1528531643
39
main.js
39
main.js
@ -217,9 +217,9 @@ ipcMain.handle('get-show-details', async (event, showId) => {
|
|||||||
throw new Error('Failed to authenticate with TVDB API: ' + loginError.message);
|
throw new Error('Failed to authenticate with TVDB API: ' + loginError.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make API request to get show extended details including seasons
|
// Make API request to get show details
|
||||||
// Using the correct endpoint structure from the API documentation
|
// Let's try a different approach - first get the show by ID using the slug or direct ID approach
|
||||||
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}`, {
|
const response = await axios.get(`https://api4.thetvdb.com/v4/series/${showId}?apikey=${apiKey}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -260,6 +260,39 @@ ipcMain.handle('get-show-details', async (event, showId) => {
|
|||||||
console.error('Error status:', error.response?.status);
|
console.error('Error status:', error.response?.status);
|
||||||
console.error('Error data:', error.response?.data);
|
console.error('Error data:', error.response?.data);
|
||||||
|
|
||||||
|
// Try a fallback approach - get the show using search by ID
|
||||||
|
try {
|
||||||
|
const searchResponse = await axios.get(`https://api4.thetvdb.com/v4/search`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
id: showId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (searchResponse.data && searchResponse.data.data && searchResponse.data.data.length > 0) {
|
||||||
|
const showData = searchResponse.data.data[0];
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
|
id: showData.id,
|
||||||
|
name: showData.name,
|
||||||
|
status: showData.status?.name,
|
||||||
|
firstAired: showData.firstAired,
|
||||||
|
overview: showData.overview,
|
||||||
|
image: showData.image,
|
||||||
|
slug: showData.slug,
|
||||||
|
seasons: [] // We'll need to fetch seasons separately if this approach works
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (fallbackError) {
|
||||||
|
console.error('Fallback approach also failed:', fallbackError.message);
|
||||||
|
}
|
||||||
|
|
||||||
return { success: false, error: 'Failed to fetch show details from TVDB API: ' + error.message };
|
return { success: false, error: 'Failed to fetch show details from TVDB API: ' + error.message };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user