File tree Expand file tree Collapse file tree
cloud-agent-next/wrapper/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -273,6 +273,28 @@ export function createConnectionManager(
273273 return false ;
274274 }
275275
276+ function getTerminalErrorText ( eventType : string , properties : Record < string , unknown > ) : string {
277+ const error = properties . error ;
278+ if ( typeof error === 'string' ) {
279+ return error ;
280+ }
281+
282+ if ( isRecord ( error ) ) {
283+ if ( typeof error . message === 'string' ) {
284+ return error . message ;
285+ }
286+
287+ const data = error . data ;
288+ if ( isRecord ( data ) && typeof data . message === 'string' ) {
289+ return data . message ;
290+ }
291+
292+ return JSON . stringify ( error ) ;
293+ }
294+
295+ return `Insufficient credits: ${ eventType } ` ;
296+ }
297+
276298 /**
277299 * Start the SDK event subscription. Runs in the background.
278300 * Replaces the old SSE consumer with a typed event stream from the SDK.
@@ -367,13 +389,7 @@ export function createConnectionManager(
367389
368390 // Terminal error detection
369391 if ( isTerminalError ( eventType , properties ) ) {
370- const errorText =
371- typeof properties . error === 'string'
372- ? properties . error
373- : properties . error
374- ? JSON . stringify ( properties . error )
375- : `Insufficient credits: ${ eventType } ` ;
376- callbacks . onTerminalError ( errorText ) ;
392+ callbacks . onTerminalError ( getTerminalErrorText ( eventType , properties ) ) ;
377393 return ;
378394 }
379395
You can’t perform that action at this time.
0 commit comments