mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 14:35:22 +08:00
463e430a3d
- Add automatic VS Code config sync when base_url changes in TOML - Improve error handling for VS Code configuration writes - Enhance state management with ref tracking to prevent duplicate API calls - Fix code formatting issues and improve readability across components - Optimize common configuration handling for both Claude and Codex providers
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
/**
|
|
* 从各种错误对象中提取错误信息
|
|
* @param error 错误对象
|
|
* @returns 提取的错误信息字符串
|
|
*/
|
|
export const extractErrorMessage = (error: unknown): string => {
|
|
if (!error) return "";
|
|
if (typeof error === "string") {
|
|
return error;
|
|
}
|
|
if (error instanceof Error && error.message.trim()) {
|
|
return error.message;
|
|
}
|
|
|
|
if (typeof error === "object") {
|
|
const errObject = error as Record<string, unknown>;
|
|
|
|
const candidate = errObject.message ?? errObject.error ?? errObject.detail;
|
|
if (typeof candidate === "string" && candidate.trim()) {
|
|
return candidate;
|
|
}
|
|
|
|
const payload = errObject.payload;
|
|
if (typeof payload === "string" && payload.trim()) {
|
|
return payload;
|
|
}
|
|
if (payload && typeof payload === "object") {
|
|
const payloadObj = payload as Record<string, unknown>;
|
|
const payloadCandidate =
|
|
payloadObj.message ?? payloadObj.error ?? payloadObj.detail;
|
|
if (typeof payloadCandidate === "string" && payloadCandidate.trim()) {
|
|
return payloadCandidate;
|
|
}
|
|
}
|
|
}
|
|
|
|
return "";
|
|
};
|