Repository navigation
fix(audio): carry CORS on the fetch-failure 500 from speech, transcription and translation - #17938
Conversation
…ption and translation When the upstream fetch itself throws (DNS failure, connection reset, TLS error), the generic catch in the three audio handlers returned errorResponse(500, ...) without CORS headers. Every upstream-error path re-applies CORS since cheaper-inference#15159 (and cheaper-inference#17844 for translations), because the canonical builders do not emit it and these routes set it only on the OPTIONS preflight. Extract the "errorResponse + CORS" step of upstreamErrorResponse into a shared audioErrorResponse helper and use it in the three catch blocks. The message is still sanitized by errorResponse.
|
Thanks, Andres. This is a tidy follow-up. Pulling the "canonical error + CORS" step out of upstreamErrorResponse into an exported audioErrorResponse() is the right shape: the existing path stays byte-for-byte the same and the three catch blocks now share it. Messages still go through errorResponse(), so sanitization is unchanged, and your test proves it by putting a credential and an absolute path into the thrown fetch error. I checked it on a clean probe of the head (2a32e58). Your new test fails 3/3 when I revert only the three handler files, and passes 3/3 with the fix. The wider audio-* and api-error-response-sanitization-15159 suites pass 163/163 on my side. The changelog fragment is there and the commits are clean. I also checked it against #17941 (the translation upstream-error change) and #17844. Both touch the Nothing blocking from my side. Two cosmetic notes, only if you feel like it: the changelog link points at the old repo path, and other fragments just use |
033f9ce
into
cheaper-inference:release/v3.8.53
Closes #17937. Follow-up suggested by the maintainer in the review of #17844.
Summary
fetchitself throws (DNS failure, connection refused, TLS error), the genericcatchinaudioSpeech.ts,audioTranscription.tsandaudioTranslation.tsreturnederrorResponse(500, ...)without CORS. Every!res.okpath on these routes re-appliesCORS_HEADERSsince fix(backend): whole-repository audit findings for v3.8.52 — 78 items (14 critical · 21 high · 29 medium · 14 keep) #15159 (fix(audio): sanitize upstream error bodies on /v1/audio/translations #17844 for translations), becauseerrorResponsedoes not emit them and the routes set CORS only on the OPTIONS preflight.upstreamErrorResponsealready did inline is now the exported helperaudioErrorResponse(status, message)inopen-sse/utils/audioResponse.ts.upstreamErrorResponsecalls it, and so do the threecatchblocks. Messages still go througherrorResponse, so sanitization is unchanged.attachOmniRouteMetaToResponseonly wrapsresponse.ok), so the headers reach the client.Not changed on purpose
catchblocks (Vertex transcription, Kie poll, MiniMax TTS, ...) and the 4xx validation errors keep their current shape. They are a separate, larger consistency question.git merge-treereports no conflict).Validation (TDD)
tests/unit/audio-fetch-failure-cors.test.ts, 3 tests (one per handler). Each stubsfetchto throw an error whose message carries a credential and an absolute path, then asserts a 500 with CORS and neither secret in the body.All
tests/unit/audio-*.test.tsplusapi-error-response-sanitization-15159: 162/163. The one failure,audio-transcriptions-combo-resolution"a combo name is expanded to its target...", fails identically on the untouched base (ReferenceError: Cannot access 'updateSettings' before initializationinside the test file).Also green:
typecheck:core, eslint on the touched files,check:file-size,check-complexity-ratchets --base-ref origin/release/v3.8.53, lint-staged /check:ai-attributionhooks.