Skip to content

Commit 9a77218

Browse files
committed
fix(wrapper): keep billing error text
1 parent e1874ea commit 9a77218

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

cloud-agent-next/wrapper/src/connection.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)