Skip to content

Commit

Permalink
improve error prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Oct 15, 2023
1 parent 4cc4144 commit 86b9b20
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/_locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "Unbefugt",
"Please login at https://chat.openai.com first": "Bitte zuerst bei https://chat.openai.com anmelden",
"Please login at https://claude.ai first": "Bitte zuerst bei https://claude.ai anmelden",
"Please login at https://bing.com first": "Bitte zuerst bei https://bing.com anmelden",
"Then open https://chat.openai.com/api/auth/session": "Dann öffne https://chat.openai.com/api/auth/sitzung",
"And refresh this page or type you question again": "Klicken Sie anschließend auf die Schaltfläche Wiederholen in der oberen rechten Ecke",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Erwägen Sie ein API-Schlüssel unter https://platform.openai.com/account/api-keys zu erstellen",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "UNAUTHORIZED",
"Please login at https://chat.openai.com first": "Please login at https://chat.openai.com first",
"Please login at https://claude.ai first": "Please login at https://claude.ai first",
"Please login at https://bing.com first": "Please login at https://bing.com first",
"Then open https://chat.openai.com/api/auth/session": "Then open https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "And click the retry button in the top right corner",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Consider creating an api key at https://platform.openai.com/account/api-keys",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/es/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "NO AUTORIZADO",
"Please login at https://chat.openai.com first": "Por favor, inicie sesión en https://chat.openai.com primero",
"Please login at https://claude.ai first": "Por favor, inicie sesión en https://claude.ai primero",
"Please login at https://bing.com first": "Por favor, inicie sesión en https://bing.com primero",
"Then open https://chat.openai.com/api/auth/session": "Luego abra https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "A continuación, pulse el botón Reintentar situado en la esquina superior derecha.",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Considere crear una clave de API en https://platform.openai.com/account/api-keys",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "NON AUTORISÉ",
"Please login at https://chat.openai.com first": "Veuillez vous connecter d'abord sur https://chat.openai.com",
"Please login at https://claude.ai first": "Veuillez vous connecter d'abord sur https://claude.ai",
"Please login at https://bing.com first": "Veuillez vous connecter d'abord sur https://bing.com",
"Then open https://chat.openai.com/api/auth/session": "Puis ouvrez https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "Cliquez ensuite sur le bouton Réessayer dans le coin supérieur droit",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Pensez à créer une clé API sur https://platform.openai.com/account/api-keys",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/in/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "TIDAK DIIZINKAN",
"Please login at https://chat.openai.com first": "Silakan masuk di https://chat.openai.com terlebih dahulu",
"Please login at https://claude.ai first": "Silakan masuk di https://claude.ai terlebih dahulu",
"Please login at https://bing.com first": "Silakan masuk di https://bing.com terlebih dahulu",
"Then open https://chat.openai.com/api/auth/session": "Lalu buka https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "Setelah itu klik tombol Coba Lagi di sudut kanan atas",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Pertimbangkan untuk membuat kunci API di https://platform.openai.com/account/api-keys",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/it/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "Non autorizzato",
"Please login at https://chat.openai.com first": "Effettua il login su https://chat.openai.com prima",
"Please login at https://claude.ai first": "Effettua il login su https://claude.ai prima",
"Please login at https://bing.com first": "Effettua il login su https://bing.com prima",
"Then open https://chat.openai.com/api/auth/session": "Quindi apri https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "Quindi fare clic sul pulsante Riprova nell'angolo in alto a destra",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Considera la creazione di una chiave API su https://platform.openai.com/account/api-keys",
Expand Down
5 changes: 3 additions & 2 deletions src/_locales/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
"Float the Window": "ウィンドウをフロート/分割表示",
"Save Conversation": "会話を保存",
"UNAUTHORIZED": "認証されていません",
"Please login at https://chat.openai.com first": "最初にhttps://chat.openai.com/にログインしてください",
"Please login at https://claude.ai first": "最初にhttps://claude.ai/にログインしてください",
"Please login at https://chat.openai.com first": "最初に https://chat.openai.com にログインしてください",
"Please login at https://claude.ai first": "最初に https://claude.ai にログインしてください",
"Please login at https://bing.com first": "最初に https://bing.com にログインしてください",
"Then open https://chat.openai.com/api/auth/session": "次にhttps://chat.openai.com/api/auth/sessionにアクセス",
"And refresh this page or type you question again": "次に、右上の「再試行」ボタンをクリックします",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "https://platform.openai.com/account/api-keysでAPIキーを作成してください",
Expand Down
5 changes: 3 additions & 2 deletions src/_locales/ko/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
"Float the Window": "창 띄우기",
"Save Conversation": "대화 저장",
"UNAUTHORIZED": "인증되지 않음",
"Please login at https://chat.openai.com first": "https://chat.openai.com에서 로그인하세요.",
"Please login at https://claude.ai first": "https://claude.ai에서 로그인하세요.",
"Please login at https://chat.openai.com first": "https://chat.openai.com 에서 로그인하세요.",
"Please login at https://claude.ai first": "https://claude.ai 에서 로그인하세요.",
"Please login at https://bing.com first": "https://bing.com 에서 로그인하세요.",
"Then open https://chat.openai.com/api/auth/session": "그런 다음 https://chat.openai.com/api/auth/session을 열거나 다시 질문을 입력하세요.",
"And refresh this page or type you question again": "그런 다음 오른쪽 상단의 재시도 버튼을 클릭합니다.",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "https://platform.openai.com/account/api-keys에서 API 키를 생성하는 것을 고려하세요.",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/pt/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "NÃO AUTORIZADO",
"Please login at https://chat.openai.com first": "Por favor, faça login em https://chat.openai.com primeiro",
"Please login at https://claude.ai first": "Por favor, faça login em https://claude.ai primeiro",
"Please login at https://bing.com first": "Por favor, faça login em https://bing.com primeiro",
"Then open https://chat.openai.com/api/auth/session": "Então, abra https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "Depois clique no botão Retry, no canto superior direito",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Considere criar uma chave de API em https://platform.openai.com/account/api-keys",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/ru/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "Несанкционированный",
"Please login at https://chat.openai.com first": "Пожалуйста, сначала войдите на https://chat.openai.com",
"Please login at https://claude.ai first": "Пожалуйста, сначала войдите на https://claude.ai",
"Please login at https://bing.com first": "Пожалуйста, сначала войдите на https://bing.com",
"Then open https://chat.openai.com/api/auth/session": "Затем откройте https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "После этого нажмите кнопку Retry в правом верхнем углу",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "Рассмотрите возможность создания ключа API на https://platform.openai.com/account/api-keys",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/tr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "Yetkilendirilmemiş",
"Please login at https://chat.openai.com first": "Lütfen önce https://chat.openai.com adresinde oturum açın",
"Please login at https://claude.ai first": "Lütfen önce https://claude.ai adresinde oturum açın",
"Please login at https://bing.com first": "Lütfen önce https://bing.com adresinde oturum açın",
"Then open https://chat.openai.com/api/auth/session": "Ardından https://chat.openai.com/api/auth/session adresini açın",
"And refresh this page or type you question again": "Ve bu sayfayı yenileyin veya sorunuzu tekrar yazın",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "https://platform.openai.com/account/api-keys adresinde bir api anahtarı oluşturmayı düşünün",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/zh-hans/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "未授权",
"Please login at https://chat.openai.com first": "请先登录 https://chat.openai.com",
"Please login at https://claude.ai first": "请先登录 https://claude.ai",
"Please login at https://bing.com first": "请先登录 https://bing.com",
"Then open https://chat.openai.com/api/auth/session": "然后打开 https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "之后点击右上角的重试按钮",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "考虑在 https://platform.openai.com/account/api-keys 创建一个API Key",
Expand Down
1 change: 1 addition & 0 deletions src/_locales/zh-hant/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"UNAUTHORIZED": "未授權",
"Please login at https://chat.openai.com first": "請先在 https://chat.openai.com 登入",
"Please login at https://claude.ai first": "請先在 https://claude.ai 登入",
"Please login at https://bing.com first": "請先在 https://bing.com 登入",
"Then open https://chat.openai.com/api/auth/session": "然後開啟 https://chat.openai.com/api/auth/session",
"And refresh this page or type you question again": "接著點擊右上角的「重試」按鈕",
"Consider creating an api key at https://platform.openai.com/account/api-keys": "建議在 https://platform.openai.com/account/api-keys 建立一個 API 金鑰",
Expand Down
27 changes: 21 additions & 6 deletions src/components/ConversationCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { v4 as uuidv4 } from 'uuid'
import { initSession } from '../../services/init-session.mjs'
import { findLastIndex } from 'lodash-es'
import { generateAnswersWithBingWebApi } from '../../services/apis/bing-web.mjs'
import { handlePortError } from '../../services/wrappers.mjs'

const logo = Browser.runtime.getURL('logo.png')

Expand Down Expand Up @@ -168,15 +169,19 @@ function ConversationCard(props) {
'error',
)
break
default:
if (conversationItemData[conversationItemData.length - 1].content.includes('gpt-loading'))
default: {
let lastItem
if (conversationItemData.length > 0)
lastItem = conversationItemData[conversationItemData.length - 1]
if (lastItem && (lastItem.content.includes('gpt-loading') || lastItem.type === 'error'))
updateAnswer(msg.error, false, 'error')
else
setConversationItemData([
...conversationItemData,
new ConversationItemData('error', msg.error),
])
break
}
}
setIsReady(true)
}
Expand Down Expand Up @@ -212,10 +217,20 @@ function ConversationCard(props) {
removeListener: () => {},
},
}
const bingToken = (await getUserConfig()).bingAccessToken
if (session.modelName.includes('bingFreeSydney'))
await generateAnswersWithBingWebApi(fakePort, session.question, session, bingToken, true)
else await generateAnswersWithBingWebApi(fakePort, session.question, session, bingToken)
try {
const bingToken = (await getUserConfig()).bingAccessToken
if (session.modelName.includes('bingFreeSydney'))
await generateAnswersWithBingWebApi(
fakePort,
session.question,
session,
bingToken,
true,
)
else await generateAnswersWithBingWebApi(fakePort, session.question, session, bingToken)
} catch (err) {
handlePortError(session, fakePort, err)
}
}
} else {
port.postMessage({ session, stop })
Expand Down
1 change: 1 addition & 0 deletions src/services/clients/bing/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class BingAIClient {
`${this.options.host}/turing/conversation/create?bundleVersion=1.864.15`,
fetchOptions,
)
if (response.status === 403) throw new Error('403 Forbidden')
const body = await response.text()
try {
const res = JSON.parse(body)
Expand Down
66 changes: 43 additions & 23 deletions src/services/wrappers.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
bingWebModelKeys,
claudeWebModelKeys,
clearOldAccessToken,
getUserConfig,
Expand Down Expand Up @@ -50,6 +51,47 @@ export async function getClaudeSessionKey() {
return (await Browser.cookies.get({ url: 'https://claude.ai/', name: 'sessionKey' }))?.value
}

export function handlePortError(session, port, err) {
console.error(err)
if (err.message) {
if (!err.message.includes('aborted')) {
if (
['message you submitted was too long', 'maximum context length'].some((m) =>
err.message.includes(m),
)
)
port.postMessage({ error: t('Exceeded maximum context length') + '\n\n' + err.message })
else if (['CaptchaChallenge', 'CAPTCHA'].some((m) => err.message.includes(m)))
port.postMessage({ error: t('Bing CaptchaChallenge') + '\n\n' + err.message })
else if (['exceeded your current quota'].some((m) => err.message.includes(m)))
port.postMessage({ error: t('Exceeded quota') + '\n\n' + err.message })
else if (['Rate limit reached'].some((m) => err.message.includes(m)))
port.postMessage({ error: t('Rate limit') + '\n\n' + err.message })
else if (['authentication token has expired'].some((m) => err.message.includes(m)))
port.postMessage({ error: 'UNAUTHORIZED' })
else if (
claudeWebModelKeys.includes(session.modelName) &&
['Invalid authorization', 'Session key required'].some((m) => err.message.includes(m))
)
port.postMessage({ error: t('Please login at https://claude.ai first') })
else if (
// `.some` for multi mode models. e.g. bingFree4-balanced
bingWebModelKeys.some((n) => session.modelName.includes(n)) &&
['/turing/conversation/create: failed to parse response body.'].some((m) =>
err.message.includes(m),
)
)
port.postMessage({ error: t('Please login at https://bing.com first') })
else port.postMessage({ error: err.message })
}
} else {
const errMsg = JSON.stringify(err)
if (bingWebModelKeys.some((n) => session.modelName.includes(n)) && errMsg.includes('isTrusted'))
port.postMessage({ error: t('Please login at https://bing.com first') })
else port.postMessage({ error: errMsg ?? 'unknown error' })
}
}

export function registerPortListener(executor) {
Browser.runtime.onConnect.addListener((port) => {
console.debug('connected')
Expand All @@ -64,29 +106,7 @@ export function registerPortListener(executor) {
try {
await executor(session, port, config)
} catch (err) {
console.error(err)
if (!err.message.includes('aborted')) {
if (
['message you submitted was too long', 'maximum context length'].some((m) =>
err.message.includes(m),
)
)
port.postMessage({ error: t('Exceeded maximum context length') + '\n\n' + err.message })
else if (['CaptchaChallenge', 'CAPTCHA'].some((m) => err.message.includes(m)))
port.postMessage({ error: t('Bing CaptchaChallenge') + '\n\n' + err.message })
else if (['exceeded your current quota'].some((m) => err.message.includes(m)))
port.postMessage({ error: t('Exceeded quota') + '\n\n' + err.message })
else if (['Rate limit reached'].some((m) => err.message.includes(m)))
port.postMessage({ error: t('Rate limit') + '\n\n' + err.message })
else if (['authentication token has expired'].some((m) => err.message.includes(m)))
port.postMessage({ error: 'UNAUTHORIZED' })
else if (
claudeWebModelKeys.includes(session.modelName) &&
['Invalid authorization'].some((m) => err.message.includes(m))
)
port.postMessage({ error: t('Please login at https://claude.ai first') })
else port.postMessage({ error: err.message })
}
handlePortError(session, port, err)
}
}

Expand Down

0 comments on commit 86b9b20

Please sign in to comment.