enhancement: better error handing for remote models when there's no internet connection (#4252)
* enhance: better handling failed to fetch * chore: remove console * chore: checking engine showing error failed to fetch * chore: fix linter * chore: fix linter error missing assistant
This commit is contained in:
parent
5d9332f23c
commit
c15bb9e9b4
@ -14,6 +14,8 @@ import ModalTroubleShooting, {
|
||||
|
||||
import { MainViewState } from '@/constants/screens'
|
||||
|
||||
import { isLocalEngine } from '@/utils/modelEngine'
|
||||
|
||||
import { mainViewStateAtom } from '@/helpers/atoms/App.atom'
|
||||
|
||||
import { selectedSettingAtom } from '@/helpers/atoms/Setting.atom'
|
||||
@ -25,53 +27,9 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
|
||||
const setSelectedSettingScreen = useSetAtom(selectedSettingAtom)
|
||||
const activeThread = useAtomValue(activeThreadAtom)
|
||||
|
||||
const getErrorTitle = () => {
|
||||
switch (message.error_code) {
|
||||
case ErrorCode.InvalidApiKey:
|
||||
case ErrorCode.AuthenticationError:
|
||||
const defaultDesc = () => {
|
||||
return (
|
||||
<span data-testid="invalid-API-key-error">
|
||||
Invalid API key. Please check your API key from{' '}
|
||||
<button
|
||||
className="font-medium text-[hsla(var(--app-link))] underline"
|
||||
onClick={() => {
|
||||
setMainState(MainViewState.Settings)
|
||||
|
||||
if (activeThread?.assistants[0]?.model.engine) {
|
||||
const engine = EngineManager.instance().get(
|
||||
activeThread.assistants[0].model.engine
|
||||
)
|
||||
engine?.name && setSelectedSettingScreen(engine.name)
|
||||
}
|
||||
}}
|
||||
>
|
||||
Settings
|
||||
</button>{' '}
|
||||
and try again.
|
||||
</span>
|
||||
)
|
||||
default:
|
||||
return (
|
||||
<p
|
||||
data-testid="passthrough-error-message"
|
||||
className="first-letter:uppercase"
|
||||
>
|
||||
{message.content[0]?.text?.value && (
|
||||
<AutoLink text={message.content[0].text.value} />
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto mt-10 max-w-[700px]">
|
||||
{message.status === MessageStatus.Error && (
|
||||
<div
|
||||
key={message.id}
|
||||
className="mx-6 flex flex-col items-center space-y-2 text-center font-medium text-[hsla(var(--text-secondary))]"
|
||||
>
|
||||
{getErrorTitle()}
|
||||
<>
|
||||
<p>
|
||||
{`Something's wrong.`} Access
|
||||
<span
|
||||
@ -83,6 +41,71 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
|
||||
now.
|
||||
</p>
|
||||
<ModalTroubleShooting />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const getEngine = () => {
|
||||
const engineName = activeThread?.assistants?.[0]?.model?.engine
|
||||
return engineName ? EngineManager.instance().get(engineName) : null
|
||||
}
|
||||
|
||||
const getErrorTitle = () => {
|
||||
const engine = getEngine()
|
||||
|
||||
switch (message.error_code) {
|
||||
case ErrorCode.InvalidApiKey:
|
||||
case ErrorCode.AuthenticationError:
|
||||
return (
|
||||
<>
|
||||
<span data-testid="invalid-API-key-error">
|
||||
Invalid API key. Please check your API key from{' '}
|
||||
<button
|
||||
className="font-medium text-[hsla(var(--app-link))] underline"
|
||||
onClick={() => {
|
||||
setMainState(MainViewState.Settings)
|
||||
engine?.name && setSelectedSettingScreen(engine.name)
|
||||
}}
|
||||
>
|
||||
Settings
|
||||
</button>{' '}
|
||||
and try again.
|
||||
</span>
|
||||
{defaultDesc()}
|
||||
</>
|
||||
)
|
||||
default:
|
||||
return (
|
||||
<p
|
||||
data-testid="passthrough-error-message"
|
||||
className="first-letter:uppercase"
|
||||
>
|
||||
{message.content[0]?.text?.value === 'Failed to fetch' &&
|
||||
engine &&
|
||||
!isLocalEngine(String(engine?.name)) ? (
|
||||
<span>
|
||||
No internet connection. <br /> Switch to an on-device model or
|
||||
check connection.
|
||||
</span>
|
||||
) : (
|
||||
<>
|
||||
<AutoLink text={message.content[0].text.value} />
|
||||
{defaultDesc()}
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto my-6 max-w-[700px]">
|
||||
{message.status === MessageStatus.Error && (
|
||||
<div
|
||||
key={message.id}
|
||||
className="mx-6 flex flex-col items-center space-y-2 text-center font-medium text-[hsla(var(--text-secondary))]"
|
||||
>
|
||||
{getErrorTitle()}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user