Skip to content

Commit 641fc0c

Browse files
committed
Handle lmsys cloudflare error
1 parent e449375 commit 641fc0c

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/app/bots/gradio/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class GradioBot extends AbstractBot {
104104
try {
105105
await wsp.open()
106106
} catch (err) {
107-
console.error('lmsys ws open error', err)
107+
console.error('WS open error', err)
108108
throw new ChatError('Failed to establish websocket connection.', ErrorCode.NETWORK_ERROR)
109109
}
110110

src/app/bots/lmsys/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import WebSocketAsPromised from 'websocket-as-promised'
22
import { GradioBot } from '../gradio'
3+
import { ChatError, ErrorCode } from '~utils/errors'
34

45
export class LMSYSBot extends GradioBot {
56
constructor(model: string) {
@@ -27,7 +28,10 @@ export class LMSYSBot extends GradioBot {
2728
resolve()
2829
}
2930
})
30-
wsp.open().catch((err) => reject(err))
31+
wsp.open().catch((err) => {
32+
console.error('lmsys ws open error', err)
33+
reject(new ChatError('Failed to establish websocket connection.', ErrorCode.LMSYS_WS_ERROR))
34+
})
3135
})
3236
}
3337

src/app/components/Chat/ErrorAction.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ const ErrorAction: FC<{ error: ChatError }> = ({ error }) => {
139139
</p>
140140
)
141141
}
142+
if (error.code === ErrorCode.LMSYS_WS_ERROR) {
143+
return (
144+
<p className="ml-2 text-secondary-text text-sm">
145+
Please visit{' '}
146+
<a href="https://chat.lmsys.org" target="_blank" rel="noreferrer" className="underline">
147+
LMSYS.org
148+
</a>{' '}
149+
and try again
150+
</p>
151+
)
152+
}
142153
if (
143154
error.code === ErrorCode.NETWORK_ERROR ||
144155
(error.code === ErrorCode.UNKOWN_ERROR && error.message.includes('Failed to fetch'))

src/utils/errors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum ErrorCode {
2121
CLAUDE_WEB_UNAVAILABLE = 'CLAUDE_WEB_UNAVAILABLE',
2222
QIANWEN_WEB_UNAUTHORIZED = 'QIANWEN_WEB_UNAUTHORIZED',
2323
BAICHUAN_WEB_UNAUTHORIZED = 'BAICHUAN_WEB_UNAUTHORIZED',
24+
LMSYS_WS_ERROR = 'LMSYS_WS_ERROR',
2425
}
2526

2627
export class ChatError extends Error {

0 commit comments

Comments
 (0)