feat: 添加错误映射以增强MIFY爬虫的错误处理
This commit is contained in:
parent
2324440aaa
commit
be136e8c13
@ -106,6 +106,11 @@ class AttachService extends NetToolBase {
|
|||||||
*/
|
*/
|
||||||
async mifyCrawler(link: string, userDescription: string) {
|
async mifyCrawler(link: string, userDescription: string) {
|
||||||
const URL = "https://mify-be.pt.xiaomi.com/api/v1/workflows/run"
|
const URL = "https://mify-be.pt.xiaomi.com/api/v1/workflows/run"
|
||||||
|
const errMap: Record<string, string> = {
|
||||||
|
crawlerErr: "网页抓取失败",
|
||||||
|
larkErr: "文档获取失败或者文档为空",
|
||||||
|
authErr: "请确保小煎蛋有对文档的读取权限,可以私发小煎蛋设置权限",
|
||||||
|
}
|
||||||
return this.post(
|
return this.post(
|
||||||
URL,
|
URL,
|
||||||
{
|
{
|
||||||
@ -124,11 +129,14 @@ class AttachService extends NetToolBase {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
const llmRes = res.data.outputs.content
|
const llmRes = res.data.outputs.content
|
||||||
if (!llmRes) throw new Error("模型总结失败")
|
if (!llmRes) throw new Error("模型总结失败")
|
||||||
if (llmRes === "crawlerErr") throw new Error("网页抓取失败")
|
if (errMap[llmRes]) throw new Error(errMap[llmRes])
|
||||||
return llmRes as string
|
return llmRes as string
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (["网页抓取失败", "模型总结失败"].includes(error.message)) {
|
if (
|
||||||
|
Object.values(errMap).includes(error.message) ||
|
||||||
|
error.message === "模型总结失败"
|
||||||
|
) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
throw new Error("MIFY爬虫请求失败")
|
throw new Error("MIFY爬虫请求失败")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user