mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-30 08:16:37 +08:00
refactor(frontend): extract reusable hooks and page helper modules
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import axios from "axios";
|
||||
|
||||
interface ErrorPayload {
|
||||
msg?: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export const isUnauthorizedError = (error: unknown): boolean => {
|
||||
return axios.isAxiosError(error) && error.response?.status === 401;
|
||||
};
|
||||
|
||||
export const extractApiErrorMessage = (
|
||||
error: unknown,
|
||||
fallback = "网络请求失败",
|
||||
): string => {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const payload = error.response?.data as ErrorPayload | undefined;
|
||||
|
||||
return payload?.msg || payload?.message || error.message || fallback;
|
||||
}
|
||||
|
||||
if (error instanceof Error && error.message) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
};
|
||||
Reference in New Issue
Block a user