commit 8acd255dd459488ac1d9346780e05dc099ba74b1
Author: Nik Afiq <nik.afiq98@ymail.com>
Date: Fri Dec 5 21:58:10 2025 +0900
Fix optional parameters handling in time parsing functions and enhance API response logging
commit 7e9a82a137057c85a909d027c51d71654ec61ac1
Author: Nik Afiq <nik.afiq98@ymail.com>
Date: Fri Dec 5 21:53:44 2025 +0900
Handle API schedule loading errors and log them for debugging
commit ec993908043c841b18fcb66916c5f9ce66b9e2f1
Author: Nik Afiq <nik.afiq98@ymail.com>
Date: Fri Dec 5 21:48:16 2025 +0900
Implement logging utility and integrate API request/response error handling
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
const envMode = (import.meta.env.VITE_APP_MODE || import.meta.env.MODE || "").toString().toLowerCase();
|
|
const enabled = envMode === "debug";
|
|
const prefix = "[watch-party]";
|
|
|
|
type Level = "debug" | "info" | "warn" | "error";
|
|
|
|
function write(level: Level, ...args: unknown[]) {
|
|
if (!enabled) return;
|
|
const fn = console[level] || console.log;
|
|
fn(prefix, ...args);
|
|
}
|
|
|
|
export const logger = {
|
|
enabled,
|
|
mode: envMode,
|
|
debug: (...args: unknown[]) => write("debug", ...args),
|
|
info: (...args: unknown[]) => write("info", ...args),
|
|
warn: (...args: unknown[]) => write("warn", ...args),
|
|
error: (...args: unknown[]) => write("error", ...args),
|
|
};
|
|
|
|
export function logApiRequest(label: string, details?: Record<string, unknown>) {
|
|
if (!enabled) return;
|
|
logger.debug(`${label}: request`, details || {});
|
|
}
|
|
|
|
export function logApiResponse(label: string, res: Response, details?: Record<string, unknown>) {
|
|
if (!enabled) return;
|
|
logger.debug(`${label}: response`, {
|
|
status: res.status,
|
|
statusText: res.statusText,
|
|
ok: res.ok,
|
|
redirected: res.redirected,
|
|
url: res.url,
|
|
...details,
|
|
});
|
|
}
|
|
|
|
export function logApiError(label: string, error: unknown) {
|
|
if (!enabled) return;
|
|
logger.error(`${label}: error`, error);
|
|
}
|