From bf3ecf0e4051a69aebb9a1b704432220c8e01946 Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Sun, 2 Aug 2026 04:56:48 +0000 Subject: [PATCH] fix: split transcription input errors --- apps/server/src/http.ts | 12 +++++++++--- apps/server/src/transcription.ts | 30 +++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/apps/server/src/http.ts b/apps/server/src/http.ts index 22372757ec..fbc9db3286 100644 --- a/apps/server/src/http.ts +++ b/apps/server/src/http.ts @@ -45,7 +45,9 @@ import { MAX_TRANSCRIPTION_AUDIO_BYTES, readTranscriptionAudio, resolveTranscriptionProvider, - TranscriptionInputError, + TranscriptionApiKeyMissingError, + TranscriptionEmptyAudioError, + TranscriptionProviderUnsupportedError, } from "./transcription.ts"; const OTLP_TRACES_PROXY_PATH = "/api/observability/v1/traces"; @@ -273,7 +275,7 @@ export const transcriptionRouteLayer = HttpRouter.add( request.headers["x-t3-transcription-provider"] ?? "", ); if (!provider) { - return yield* new TranscriptionInputError({ reason: "invalid_provider" }); + return yield* new TranscriptionProviderUnsupportedError(); } const audio = yield* readTranscriptionAudio(request.stream); @@ -291,12 +293,16 @@ export const transcriptionRouteLayer = HttpRouter.add( EnvironmentScopeRequiredError: HttpServerRespondable.toResponse, TranscriptionAudioTooLargeError: (error) => Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 413 })), + TranscriptionApiKeyMissingError: (error) => + Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 400 })), TranscriptionBodyReadError: (error) => Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 400 })), - TranscriptionInputError: (error) => + TranscriptionEmptyAudioError: (error) => Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 400 })), TranscriptionProviderError: (error) => Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 502 })), + TranscriptionProviderUnsupportedError: (error) => + Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 400 })), TranscriptionRequestError: (error) => Effect.succeed(HttpServerResponse.jsonUnsafe({ error: error.message }, { status: 502 })), TranscriptionResponseError: (error) => diff --git a/apps/server/src/transcription.ts b/apps/server/src/transcription.ts index 3fc111289f..ee488408be 100644 --- a/apps/server/src/transcription.ts +++ b/apps/server/src/transcription.ts @@ -42,13 +42,29 @@ export class TranscriptionBodyReadError extends Schema.TaggedErrorClass()( - "TranscriptionInputError", - { reason: Schema.Literals(["empty_audio", "invalid_provider", "missing_api_key"]) }, +export class TranscriptionEmptyAudioError extends Schema.TaggedErrorClass()( + "TranscriptionEmptyAudioError", + {}, +) { + override get message(): string { + return "The recording was empty."; + } +} + +export class TranscriptionProviderUnsupportedError extends Schema.TaggedErrorClass()( + "TranscriptionProviderUnsupportedError", + {}, +) { + override get message(): string { + return "Select OpenAI or Groq for transcription."; + } +} + +export class TranscriptionApiKeyMissingError extends Schema.TaggedErrorClass()( + "TranscriptionApiKeyMissingError", + {}, ) { override get message(): string { - if (this.reason === "empty_audio") return "The recording was empty."; - if (this.reason === "invalid_provider") return "Select OpenAI or Groq for transcription."; return "Add an API key for the selected transcription provider."; } } @@ -133,7 +149,7 @@ export const forwardVoiceTranscription = Effect.fn("voiceTranscription.forward") input: VoiceTranscriptionInput, ) { if (input.audio.byteLength === 0) { - return yield* new TranscriptionInputError({ reason: "empty_audio" }); + return yield* new TranscriptionEmptyAudioError(); } if (input.audio.byteLength > MAX_TRANSCRIPTION_AUDIO_BYTES) { return yield* new TranscriptionAudioTooLargeError({ @@ -142,7 +158,7 @@ export const forwardVoiceTranscription = Effect.fn("voiceTranscription.forward") } const apiKey = input.apiKey.trim(); if (!apiKey) { - return yield* new TranscriptionInputError({ reason: "missing_api_key" }); + return yield* new TranscriptionApiKeyMissingError(); } const providerConfig = transcriptionProviderConfig(input.provider);