mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-21 03:44:21 +00:00
feat: 转义状态码
This commit is contained in:
@@ -7,6 +7,14 @@ import fetch from 'node-fetch'
|
|||||||
import { sendResponse } from '../utils'
|
import { sendResponse } from '../utils'
|
||||||
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
||||||
|
|
||||||
|
const ErrorCodeMessage: Record<string, string> = {
|
||||||
|
401: '提供错误的API密钥 | Incorrect API key provided',
|
||||||
|
429: '服务器限流,请稍后再试 | Server was limited, please try again later',
|
||||||
|
503: '服务器繁忙,请稍后再试 | Server is busy, please try again later',
|
||||||
|
500: '服务器繁忙,请稍后再试 | Server is busy, please try again later',
|
||||||
|
403: '服务器拒绝访问,请稍后再试 | Server refused to access, please try again later',
|
||||||
|
}
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
||||||
@@ -98,8 +106,10 @@ async function chatReplyProcess(
|
|||||||
return sendResponse({ type: 'Success', data: response })
|
return sendResponse({ type: 'Success', data: response })
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
global.console.error(error)
|
const code = error.statusCode || 'unknown'
|
||||||
return sendResponse({ type: 'Fail', message: error.message })
|
if (Reflect.has(ErrorCodeMessage, code))
|
||||||
|
return sendResponse({ type: 'Fail', message: ErrorCodeMessage[code] })
|
||||||
|
return sendResponse({ type: 'Fail', message: `${error.statusCode}-${error.statusText}` })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user