260623_01_ENH: 엑셀 다운로드를 제외한 기능 완성

This commit is contained in:
2026-06-23 09:54:25 +09:00
parent 28da30b865
commit 08ea4d5420
23 changed files with 1202 additions and 349 deletions

View File

@@ -102,6 +102,20 @@ const isJsonContentType = (ctype: string) => {
return ct.includes("application/json") || ct.includes("+json")
}
const getErrorMessage = (data: unknown) => {
if (typeof data === "object" && data !== null) {
const error = data as { detail?: unknown; message?: unknown; errMessage?: unknown };
return (
(typeof error.detail === "string" && error.detail) ||
(typeof error.message === "string" && error.message) ||
(typeof error.errMessage === "string" && error.errMessage) ||
undefined
);
}
return typeof data === "string" && data ? data : undefined;
};
export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {}) => {
const {
getToken,
@@ -179,7 +193,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
}
const autoLogout = options.autoLogoutOnAuthError ?? true;
const suppressAlert = options.suppressAlert ?? true;
const suppressAlert = options.suppressAlert ?? options.method === "GET";
if (res.status === 401) options.onAuthError?.();
@@ -191,12 +205,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
}
if (!suppressAlert && typeof window !== "undefined") {
const serverMsg =
typeof parsedError === "object" && parsedError !== null && "message" in parsedError
? String((parsedError as { message?: unknown }).message ?? "")
: typeof parsedError === "string"
? parsedError
: undefined;
const serverMsg = getErrorMessage(parsedError);
const msg = setErrorMessage?.(res.status, serverMsg) ?? (serverMsg ?? `HTTP ${res.status}`);
alert(`[${res.status}] ${msg}`);
@@ -223,7 +232,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
if (!res.ok) {
const autoLogout = options.autoLogoutOnAuthError ?? true;
const suppressAlert = options.suppressAlert ?? true;
const suppressAlert = options.suppressAlert ?? options.method === "GET";
if (res.status === 401) options.onAuthError?.();
@@ -235,12 +244,7 @@ export const createHttpClient = (baseURL: string, opts: HttpClientOptions = {})
}
if (!suppressAlert && typeof window !== "undefined") {
const serverMsg =
typeof parsed === "object" && parsed !== null && "message" in parsed
? String((parsed as { message?: unknown }).message ?? "")
: typeof parsed === "string"
? parsed
: undefined;
const serverMsg = getErrorMessage(parsed);
const msg = setErrorMessage?.(res.status, serverMsg) ?? (serverMsg ?? `HTTP ${res.status}`);
alert(`[${res.status}] ${msg}`);