Skip to content

Commit 56f6254

Browse files
committed
Handle Bard unauthorized error
1 parent 15e8a99 commit 56f6254

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/app/bots/bard/api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export async function fetchRequestParams() {
1313
})
1414
const atValue = extractFromHTML('SNlM0e', html)
1515
const blValue = extractFromHTML('cfb2h', html)
16+
17+
if (!atValue) {
18+
throw new ChatError('There is no logged-in Google account in this browser', ErrorCode.BARD_UNAUTHORIZED)
19+
}
20+
1621
return { atValue, blValue }
1722
}
1823

src/app/components/Chat/ErrorAction.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ const ErrorAction: FC<{ error: ChatError }> = ({ error }) => {
109109
</a>
110110
)
111111
}
112+
if (error.code === ErrorCode.BARD_UNAUTHORIZED) {
113+
return (
114+
<a href="https://bard.google.com" target="_blank" rel="noreferrer">
115+
<ActionButton text={t('Login to bard.google.com')} />
116+
</a>
117+
)
118+
}
112119
if (error.code === ErrorCode.CHATGPT_CLOUDFLARE || error.code === ErrorCode.CHATGPT_UNAUTHORIZED) {
113120
return <ChatGPTAuthErrorAction />
114121
}

src/utils/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum ErrorCode {
99
BING_CAPTCHA = 'BING_CAPTCHA',
1010
API_KEY_NOT_SET = 'API_KEY_NOT_SET',
1111
BARD_EMPTY_RESPONSE = 'BARD_EMPTY_RESPONSE',
12+
BARD_UNAUTHORIZED = 'BARD_UNAUTHORIZED',
1213
MISSING_POE_HOST_PERMISSION = 'MISSING_POE_HOST_PERMISSION',
1314
POE_UNAUTHORIZED = 'POE_UNAUTHORIZED',
1415
MISSING_HOST_PERMISSION = 'MISSING_HOST_PERMISSION',

0 commit comments

Comments
 (0)