Skip to content

Commit

Permalink
feat: 完善错误信息
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Aug 18, 2023
1 parent 5d09d9f commit d2c97db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/components/chat-notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ function getAction(error: ChatError, reset: () => void) {
</div>
)
}
if (error.code === ErrorCode.BING_IP_FORBIDDEN) {
return (
<ExternalLink href="https://github.com/weaigc/bingo/issues">
你的服务器或代理已被封禁,请更换服务器或使用代理重试
</ExternalLink>
)
}
if (error.code === ErrorCode.BING_FORBIDDEN) {
return (
<ExternalLink href="https://bing.com/new">
Expand Down
5 changes: 4 additions & 1 deletion src/lib/bots/bing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ export class BingWebBot {
}

if (!resp?.result) {
throw new ChatError('你的 VPS 或代理可能被封禁,如有疑问,请前往 https://github.com/weaigc/bingo 咨询', ErrorCode.UNKOWN_ERROR)
throw new ChatError('你的 VPS 或代理可能被封禁,如有疑问,请前往 https://github.com/weaigc/bingo 咨询', ErrorCode.BING_IP_FORBIDDEN)
}

const { value, message } = resp.result || {}
if (value !== 'Success') {
const errorMsg = `${value}: ${message}`
if (value === 'UnauthorizedRequest') {
if (/fetch failed/i.test(message || '')) {
throw new ChatError(errorMsg, ErrorCode.BING_IP_FORBIDDEN)
}
throw new ChatError(errorMsg, ErrorCode.BING_UNAUTHORIZED)
}
if (value === 'Forbidden') {
Expand Down
1 change: 1 addition & 0 deletions src/lib/bots/bing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum BingConversationStyle {
export enum ErrorCode {
CONVERSATION_LIMIT = 'CONVERSATION_LIMIT',
BING_UNAUTHORIZED = 'BING_UNAUTHORIZED',
BING_IP_FORBIDDEN = 'BING_IP_FORBIDDEN',
BING_FORBIDDEN = 'BING_FORBIDDEN',
BING_CAPTCHA = 'BING_CAPTCHA',
THROTTLE_LIMIT = 'THROTTLE_LIMIT',
Expand Down

0 comments on commit d2c97db

Please sign in to comment.