Skip to content

Commit 433ceff

Browse files
Miriadresearch
andcommitted
fix: wrap discoverTrends() in try/catch for graceful fallback
If trend discovery throws (network error, API down, etc.), falls back to FALLBACK_TRENDS instead of returning a 500. Matches the same resilient pattern used for conductResearch(). Co-authored-by: research <research@miriad.systems>
1 parent 69a9e8b commit 433ceff

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/api/cron/ingest/route.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,16 @@ export async function GET(request: NextRequest) {
383383
try {
384384
// Step 1: Discover trending topics (replaces fetchTrendingTopics)
385385
console.log("[CRON/ingest] Discovering trending topics...");
386-
let trends = await discoverTrends({ lookbackDays: 7, maxTopics: 10 });
387-
console.log(`[CRON/ingest] Found ${trends.length} trending topics`);
386+
let trends: TrendResult[];
387+
try {
388+
trends = await discoverTrends({ lookbackDays: 7, maxTopics: 10 });
389+
console.log(`[CRON/ingest] Found ${trends.length} trending topics`);
390+
} catch (err) {
391+
console.warn("[CRON/ingest] Trend discovery failed, using fallback topics:", err);
392+
trends = [];
393+
}
388394

389-
// Fall back to hardcoded topics if discovery returns empty
395+
// Fall back to hardcoded topics if discovery returns empty or failed
390396
if (trends.length === 0) {
391397
console.warn("[CRON/ingest] No trends discovered, using fallback topics");
392398
trends = FALLBACK_TRENDS;

0 commit comments

Comments
 (0)