@@ -0,0 +1,27 @@
|
||||
/** 获取错误消息 */
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user