fix: friendly 502 handling, 2 uvicorn workers, file bundle cache (0.20.18)

This commit is contained in:
2026-06-20 20:01:46 +10:00
parent 4d9a9e7e2b
commit f3a8952947
8 changed files with 63 additions and 40 deletions
+20 -5
View File
@@ -62,20 +62,20 @@ export async function apiFetch<T>(path: string, init: RequestInit = {}): Promise
clearToken();
redirectToErrorPage(401);
}
throw new ApiError(parseApiError(text) || "Unauthorized", 401);
throw new ApiError(parseApiError(text, 401) || "Unauthorized", 401);
}
if (res.status === 403) {
if (hadToken) {
redirectToErrorPage(403);
}
throw new ApiError(parseApiError(text) || "Forbidden", 403);
throw new ApiError(parseApiError(text, 403) || "Forbidden", 403);
}
if (res.status === 429) {
redirectToErrorPage(429);
throw new ApiError(parseApiError(text) || "Too many requests", 429);
throw new ApiError(parseApiError(text, 429) || "Too many requests", 429);
}
if (!res.ok) {
throw new ApiError(parseApiError(text) || res.statusText, res.status);
throw new ApiError(parseApiError(text, res.status) || res.statusText, res.status);
}
if (!text) {
return undefined as T;
@@ -99,8 +99,23 @@ export function fetchMe(): Promise<MeResponse> {
return apiFetch<MeResponse>("/api/v1/auth/me");
}
export function parseApiError(text: string): string {
export function parseApiError(text: string, status?: number): string {
if (status === 502 || status === 503 || status === 504) {
if (/<title>\s*502 Bad Gateway/i.test(text) || /502 Bad Gateway/i.test(text)) {
return "Сервер SAC временно недоступен (перезапуск или обновление). Подождите 5–10 секунд и обновите страницу.";
}
if (/<title>\s*503 Service Unavailable/i.test(text) || /503 Service Unavailable/i.test(text)) {
return "SAC временно перегружен. Повторите запрос через несколько секунд.";
}
if (/<title>\s*504 Gateway Time-out/i.test(text) || /504 Gateway Time-out/i.test(text)) {
return "Превышено время ожидания ответа SAC. Долгая операция могла ещё выполняться на сервере.";
}
return "Временная ошибка шлюза SAC. Обновите страницу.";
}
if (!text) return "";
if (text.trimStart().startsWith("<")) {
return status ? `Ошибка HTTP ${status}` : "Ошибка сервера";
}
try {
const data = JSON.parse(text) as { detail?: string | Array<{ msg?: string }> };
if (typeof data.detail === "string") return data.detail;