fix(backend): stop showing the clinician null, NaN and the wrong failure

Two ways a voice failure described itself wrongly.

describe() built the quoted-back text from fields that are all nullable on
the wire, and toVoiceIntent casts rather than checks — so a half-classified
deadline rendered as “null null” — not a usable date, and an offset with no
amount as “+NaN day”. Blank is already handled by the sheet; it now falls
back to that.

The DTO's constraints resolved to unrelated codes: maxLength fell through
to VALIDATION_FIELD_REQUIRED, so an oversized recording said a field was
missing, and isIn maps to VALIDATION_LANGUAGE_INVALID, so an unsupported
container said the language was invalid. Both now name their own code —
the validation factory already returns a message verbatim when it is itself
a known ErrorCode, so this needs no change to the shared mapping.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-21 05:04:30 +08:00
parent 118853ce73
commit 78e756b78f
7 changed files with 72 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import {
MaxLength,
Min,
} from 'class-validator';
import { ErrorCode } from '../../../common/errors/error-codes';
/** Containers OpenRouter's transcription endpoint accepts, and MediaRecorder can produce. */
export const VOICE_AUDIO_FORMATS = [
@@ -32,10 +33,14 @@ export class ExtractVoiceDto {
*/
@IsString()
@IsBase64()
@MaxLength(8_000_000)
// Both constraints name their own code. Left to the default mapping, `maxLength` falls
// through to VALIDATION_FIELD_REQUIRED and `isIn` resolves to
// VALIDATION_LANGUAGE_INVALID — so an oversized recording told the clinician a field
// was missing, and an unsupported container told them their language was invalid.
@MaxLength(8_000_000, { message: ErrorCode.VOICE_CLIP_TOO_LONG })
audio: string;
@IsIn(VOICE_AUDIO_FORMATS)
@IsIn(VOICE_AUDIO_FORMATS, { message: ErrorCode.VOICE_UNSUPPORTED_FORMAT })
format: VoiceAudioFormat;
/**