@@ -460,6 +460,16 @@ class ParaformerRealtimeSession implements IRealtimeSession {
460460 }
461461}
462462
463+ /** Extract human-readable error from API response body (JSON or plain text) */
464+ function parseApiError ( status : number , body : string ) : string {
465+ try {
466+ const json = JSON . parse ( body ) ;
467+ const msg = json ?. error ?. message || json ?. message || json ?. error || '' ;
468+ if ( msg ) return `${ status } : ${ typeof msg === 'string' ? msg : JSON . stringify ( msg ) } ` ;
469+ } catch { }
470+ return `${ status } : ${ body . slice ( 0 , 200 ) } ` ;
471+ }
472+
463473// ═════════════════════════════════════════════════════════════════════════════
464474// STTService — public API
465475// ═════════════════════════════════════════════════════════════════════════════
@@ -522,8 +532,7 @@ export class STTService {
522532 } ) ;
523533
524534 if ( ! res . ok ) {
525- const err = await res . text ( ) ;
526- throw new Error ( `DashScope STT ${ res . status } : ${ err . slice ( 0 , 300 ) } ` ) ;
535+ throw new Error ( `DashScope STT ${ parseApiError ( res . status , await res . text ( ) . catch ( ( ) => '' ) ) } ` ) ;
527536 }
528537
529538 const json = await res . json ( ) ;
@@ -555,8 +564,7 @@ export class STTService {
555564 } ) ;
556565
557566 if ( ! res . ok ) {
558- const err = await res . text ( ) ;
559- throw new Error ( `STT ${ res . status } : ${ err . slice ( 0 , 300 ) } ` ) ;
567+ throw new Error ( `STT ${ parseApiError ( res . status , await res . text ( ) . catch ( ( ) => '' ) ) } ` ) ;
560568 }
561569
562570 const json = await res . json ( ) ;
0 commit comments