Skip to content

Commit

Permalink
Handle Bard unauthorized error
Browse files Browse the repository at this point in the history
  • Loading branch information
wong2 committed Dec 5, 2023
1 parent 15e8a99 commit 56f6254
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/bots/bard/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export async function fetchRequestParams() {
})
const atValue = extractFromHTML('SNlM0e', html)
const blValue = extractFromHTML('cfb2h', html)

if (!atValue) {
throw new ChatError('There is no logged-in Google account in this browser', ErrorCode.BARD_UNAUTHORIZED)
}

return { atValue, blValue }
}

Expand Down
7 changes: 7 additions & 0 deletions src/app/components/Chat/ErrorAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ const ErrorAction: FC<{ error: ChatError }> = ({ error }) => {
</a>
)
}
if (error.code === ErrorCode.BARD_UNAUTHORIZED) {
return (
<a href="https://bard.google.com" target="_blank" rel="noreferrer">
<ActionButton text={t('Login to bard.google.com')} />
</a>
)
}
if (error.code === ErrorCode.CHATGPT_CLOUDFLARE || error.code === ErrorCode.CHATGPT_UNAUTHORIZED) {
return <ChatGPTAuthErrorAction />
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum ErrorCode {
BING_CAPTCHA = 'BING_CAPTCHA',
API_KEY_NOT_SET = 'API_KEY_NOT_SET',
BARD_EMPTY_RESPONSE = 'BARD_EMPTY_RESPONSE',
BARD_UNAUTHORIZED = 'BARD_UNAUTHORIZED',
MISSING_POE_HOST_PERMISSION = 'MISSING_POE_HOST_PERMISSION',
POE_UNAUTHORIZED = 'POE_UNAUTHORIZED',
MISSING_HOST_PERMISSION = 'MISSING_HOST_PERMISSION',
Expand Down

0 comments on commit 56f6254

Please sign in to comment.