Skip to content

Commit 6d96e40

Browse files
committed
Handle retry error instance
1 parent bae8eb2 commit 6d96e40

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

apps/studio/electron/main/chat/index.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { MainChannels } from '@onlook/models/constants';
1414
import {
1515
generateObject,
16+
RetryError,
1617
streamText,
1718
type CoreMessage,
1819
type CoreSystemMessage,
@@ -125,9 +126,13 @@ class LlmManager {
125126
};
126127
}
127128
}
128-
console.log('C', error.error.lastError.responseBody);
129-
const errorMessage = JSON.parse(error.error.lastError.responseBody).error.message;
130-
return { message: errorMessage, type: 'error' };
129+
130+
if (RetryError.isInstance(error.error)) {
131+
const parsed = JSON.parse(error.error.lastError.responseBody);
132+
return { message: parsed.error.message, type: 'error' };
133+
}
134+
135+
return { message: JSON.stringify(error), type: 'error' };
131136
} catch (parseError) {
132137
console.error('Error parsing error', parseError);
133138
return { message: JSON.stringify(parseError), type: 'error' };
@@ -154,26 +159,6 @@ class LlmManager {
154159
mainWindow?.webContents.send(MainChannels.CHAT_STREAM_PARTIAL, res);
155160
}
156161

157-
private getErrorMessage(error: any): string {
158-
if (error instanceof Error) {
159-
return error.message;
160-
}
161-
if (typeof error === 'string') {
162-
return error;
163-
}
164-
if (error instanceof Response) {
165-
return error.statusText;
166-
}
167-
if (error && typeof error === 'object' && 'message' in error) {
168-
return String(error.message);
169-
}
170-
171-
if (error?.error?.lastError?.responseBody) {
172-
return JSON.parse(error.error.lastError.responseBody).error;
173-
}
174-
return JSON.stringify(error);
175-
}
176-
177162
public async generateSuggestions(messages: CoreMessage[]): Promise<ChatSuggestion[]> {
178163
try {
179164
const model = await initModel(LLMProvider.ANTHROPIC, CLAUDE_MODELS.HAIKU, {

0 commit comments

Comments
 (0)