From eb6821ca76e2e0e2c089d6c3d2268ee92bab3463 Mon Sep 17 00:00:00 2001 From: R0m1k3 Date: Thu, 16 Apr 2026 11:29:55 +0200 Subject: [PATCH] Corrige TypeError dans subscribeFromDiscovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit result.podcast est un plain object (toJSON()), appeler .toJSON() dessus crashe. Fix: refetch le podcast depuis MongoDB après création pour avoir un vrai Document Mongoose. Co-Authored-By: Claude Sonnet 4.6 --- backend/src/controllers/podcastController.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/controllers/podcastController.ts b/backend/src/controllers/podcastController.ts index d8f7b6f..cfcb488 100644 --- a/backend/src/controllers/podcastController.ts +++ b/backend/src/controllers/podcastController.ts @@ -197,7 +197,7 @@ export const subscribeFromDiscovery = async (req: Request, res: Response) => { // Check if podcast already in database let podcast = await Podcast.findOne({ rssUrl }); - // If not in database, try to fetch and create it + // If not in database, create it from RSS if (!podcast) { try { const result = await rssParserService.createPodcastFromRss(rssUrl, { @@ -207,21 +207,21 @@ export const subscribeFromDiscovery = async (req: Request, res: Response) => { imageUrl: imageUrl, episodes: [], }); - podcast = result.podcast; + // Refetch as a proper Mongoose document (result.podcast is a plain object) + podcast = await Podcast.findById(result.podcast._id); } catch (error: any) { - // If podcast creation fails, create minimal entry if (error.message.includes('already in database')) { podcast = await Podcast.findOne({ rssUrl }); } else { return res.status(400).json({ - message: `Failed to fetch podcast: ${error.message}`, + message: `Impossible de récupérer le podcast : ${error.message}`, }); } } } if (!podcast) { - return res.status(400).json({ message: 'Failed to add podcast' }); + return res.status(400).json({ message: "Impossible d'ajouter le podcast" }); } // Check if already subscribed