Skip to content

Commit 84f5698

Browse files
committed
fix: handle no available WebSocket endpoints gracefully
1 parent bf4d936 commit 84f5698

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

app/api/transcription/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ async function updateHealthyEndpoints(): Promise<void> {
8585
/**
8686
* Get the next healthy WebSocket endpoint in round-robin fashion
8787
*/
88-
function getNextEndpoint(): string {
88+
function getNextEndpoint(): string | null {
8989
if (healthyEndpoints.length === 0) {
9090
healthyEndpoints = [...WS_TRANSCRIPTION_URLS];
9191
}
9292

9393
if (healthyEndpoints.length === 0) {
94-
throw new Error('No WebSocket transcription endpoints configured');
94+
return null;
9595
}
9696

9797
const endpoint = healthyEndpoints[currentIndex];
@@ -108,7 +108,14 @@ async function handleGetRequest() {
108108
await updateHealthyEndpoints();
109109

110110
const endpoint = getNextEndpoint();
111-
111+
112+
if (!endpoint) {
113+
return NextResponse.json(
114+
{ error: 'No transcription endpoints configured' },
115+
{ status: 503 }
116+
);
117+
}
118+
112119
return NextResponse.json({
113120
url: endpoint,
114121
healthyEndpoints: healthyEndpoints.length,

0 commit comments

Comments
 (0)