diff --git a/web/containers/ErrorMessage/index.tsx b/web/containers/ErrorMessage/index.tsx index b2f6bc23a..96ced0ac5 100644 --- a/web/containers/ErrorMessage/index.tsx +++ b/web/containers/ErrorMessage/index.tsx @@ -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,30 +27,52 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { const setSelectedSettingScreen = useSetAtom(selectedSettingAtom) const activeThread = useAtomValue(activeThreadAtom) + const defaultDesc = () => { + return ( + <> +

+ {`Something's wrong.`} Access  + setModalTroubleShooting(true)} + > + troubleshooting assistance + +  now. +

+ + + ) + } + + 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 ( - - Invalid API key. Please check your API key from{' '} - {' '} - and try again. - + }} + > + Settings + {' '} + and try again. + + {defaultDesc()} + ) default: return ( @@ -56,8 +80,18 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { data-testid="passthrough-error-message" className="first-letter:uppercase" > - {message.content[0]?.text?.value && ( - + {message.content[0]?.text?.value === 'Failed to fetch' && + engine && + !isLocalEngine(String(engine?.name)) ? ( + + No internet connection.
Switch to an on-device model or + check connection. +
+ ) : ( + <> + + {defaultDesc()} + )}

) @@ -65,24 +99,13 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { } return ( -
+
{message.status === MessageStatus.Error && (
{getErrorTitle()} -

- {`Something's wrong.`} Access  - setModalTroubleShooting(true)} - > - troubleshooting assistance - -  now. -

-
)}