MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / extractErrorMessage

Function extractErrorMessage

ai/ai.ts:543–565  ·  view source on GitHub ↗
(error: any)

Source from the content-addressed store, hash-verified

541
542const extractErrorMessage = (error: any): string => {
543 const msgText = typeof error?.message === "string" ? error.message : "";
544 const reasonText =
545 typeof error?.cause === "string"
546 ? error.cause
547 : error?.cause
548 ? String(error.cause)
549 : error?.config?.signal?.reason
550 ? String(error.config.signal.reason)
551 : "";
552
553 if ((msgText + reasonText).includes("请求超时")) return "请求超时";
554 if (error?.name === "AbortError" || msgText.toLowerCase().includes("aborted"))
555 return "操作已取消";
556 if (error?.code === "ECONNABORTED") return "请求超时";
557 if (error?.response?.status === 429) return "请求过于频繁,请稍后重试";
558 return (
559 error?.response?.data?.error?.message ||
560 error?.response?.data?.message ||
561 msgText ||
562 "未知错误"
563 );
564};
565
566class UserError extends Error {
567 constructor(message: string) {
568 super(message);

Callers 1

formatErrorForDisplayFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected