From 960e1f1610d993cb5fbc8e8d566bccc330b8b69d Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 7 Aug 2024 21:13:00 +0800 Subject: [PATCH] improve claude web error prompt --- src/services/clients/claude/index.mjs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/clients/claude/index.mjs b/src/services/clients/claude/index.mjs index e409fd8..0da62f3 100644 --- a/src/services/clients/claude/index.mjs +++ b/src/services/clients/claude/index.mjs @@ -188,7 +188,7 @@ export class Claude { async init() { const organizations = await this.getOrganizations() if (organizations.error) { - throw new Error(JSON.stringify(organizations, null, 2)) + throw new Error(organizations.error) } this.organizationId = organizations[0].uuid this.recent_conversations = await this.getConversations() @@ -222,7 +222,19 @@ export class Claude { cookie: `sessionKey=${this.sessionKey}`, }, }) - return await response.json().catch(errorHandle('getOrganizations')) + const responseText = await response.text() + if (responseText.includes('available in certain regions')) + return { + error: 'Claude.ai is not available in your region', + } + try { + return JSON.parse(responseText) + } catch (e) { + errorHandle('getOrganizations')(e) + return { + error: 'failed to parse response', + } + } } /** * Delete all conversations