From 9ac832545d7e1f6fb416a6f72f5f324008986261 Mon Sep 17 00:00:00 2001 From: Jos Vooges | STH Date: Tue, 22 Sep 2026 04:20:55 +0200 Subject: [PATCH] Map F1TV play failures to clear AppErrors instead of INTERNAL_ERROR. Upcoming agenda sessions were hitting CONTENT/PLAY and surfacing a generic 500 to the TV app. --- apps/master-api/src/f1tv/play.ts | 47 +++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/apps/master-api/src/f1tv/play.ts b/apps/master-api/src/f1tv/play.ts index cb04714..24d1a34 100644 --- a/apps/master-api/src/f1tv/play.ts +++ b/apps/master-api/src/f1tv/play.ts @@ -42,22 +42,43 @@ export async function resolveF1tvPlay( const preferredChannel = opts?.channelId ?? session?.defaultChannelId ?? 1033; - const played = await fetchContentPlay({ - contentId, - channelId: preferredChannel, - auth: { - ascendontoken: account.ascendontoken, - entitlementtoken: account.entitlementtoken, - sessionId: ensureSessionId(account.sessionId), - }, - locale: config.locale, - playPlatform: "WEB_HLS", - timeoutMs: config.syncTimeoutMs, - }); + let played: Awaited>; + try { + played = await fetchContentPlay({ + contentId, + channelId: preferredChannel, + auth: { + ascendontoken: account.ascendontoken, + entitlementtoken: account.entitlementtoken, + sessionId: ensureSessionId(account.sessionId), + }, + locale: config.locale, + playPlatform: "WEB_HLS", + timeoutMs: config.syncTimeoutMs, + }); + } catch (err) { + const msg = err instanceof Error ? err.message : String(err); + if (/HTTP 4\d\d|NOT_FOUND|UNAVAILABLE|FORBIDDEN/i.test(msg)) { + throw new AppError( + "NOT_READY", + session?.kind === "live_event" && session.startMs > Date.now() + ? "Dit event is nog niet begonnen" + : "F1TV-stream is nu niet beschikbaar", + 409 + ); + } + throw new AppError("UPSTREAM_ERROR", `F1TV play mislukt: ${msg.slice(0, 160)}`, 502); + } const feed = pickDefaultFeed(played.feeds, preferredChannel); if (!feed?.url) { - throw new AppError("NOT_READY", "Geen F1TV-stream-URL ontvangen", 409); + throw new AppError( + "NOT_READY", + session?.kind === "live_event" && session.startMs > Date.now() + ? "Dit event is nog niet begonnen" + : "Geen F1TV-stream-URL ontvangen", + 409 + ); } return {