5294528148
Co-authored-by: Copilot <copilot@github.com>
28 lines
578 B
TypeScript
28 lines
578 B
TypeScript
/** 获取错误消息 */
|
|
export const getErrorMessage = (error: unknown, fallbackMessage: string) => {
|
|
const fetchError = error as {
|
|
data?: unknown;
|
|
message?: string;
|
|
response?: {
|
|
_data?: unknown;
|
|
};
|
|
};
|
|
|
|
const errorData = fetchError.data ?? fetchError.response?._data;
|
|
|
|
if (typeof errorData === "string") {
|
|
return errorData;
|
|
}
|
|
|
|
if (
|
|
errorData &&
|
|
typeof errorData === "object" &&
|
|
"msg" in errorData &&
|
|
typeof errorData.msg === "string"
|
|
) {
|
|
return errorData.msg;
|
|
}
|
|
|
|
return fetchError.message || fallbackMessage;
|
|
};
|