Support new backend contracts: single-flight refresh, ad impression tokens, error handling

- apiFetch: proactive refresh, cross-tab single-flight via Web Locks, no logout on transient errors
- AuthContext: save tokens returned on own login change, revoke refresh on logout, sync tabs
- Ads: X-Session-Id, impressionToken in impression/click, IAB viewability, safe http(s) targetUrl
- STOMP: refresh before CONNECT, stop reconnect loop on dead session, /user/queue/errors behind flag
- Auth form: password 8 chars / 72 bytes; 429/413 messages via describeApiError
- My posts with auth + moderation badges; post form step validation and field limits
- Map: escape user text in Yandex hint/template

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SlimusMinus
2026-10-20 02:03:42 +03:00
parent 67de963d6d
commit db37befb8d
34 changed files with 1005 additions and 260 deletions

View File

@@ -2,6 +2,7 @@ import { useState } from "react";
import { useTranslation } from 'react-i18next';
import { API_URL } from "../config/authConstants";
import { apiFetch } from "../api/apiClient";
import { describeApiError, readApiError } from "../api/apiErrors";
/**
* Универсальная мутация для создания и обновления объявления.
@@ -51,21 +52,23 @@ export function usePostMutation({ adminMode = false } = {}) {
});
if (!res.ok) {
let body;
try { body = await res.json(); } catch { body = null; }
const apiError = await readApiError(res);
if (body?.error === "CONTENT_BLOCKED") {
return { blocked: true, reason: body.reason || "" };
// Причина блокировки — в message, метки модели — в details.labels
if (apiError.code === "CONTENT_BLOCKED") {
return { blocked: true, reason: apiError.serverMessage };
}
throw new Error(body?.message || t('post.serverError', { status: res.status }));
// 429 — лимит создания объявлений (20 в час), 413 — слишком большие
// фото, 400 — текст проверки полей с сервера
throw new Error(describeApiError(apiError, t('post.serverError', { status: res.status })));
}
let payload = null;
try { payload = await res.json(); } catch { payload = null; }
return { ok: true, data: payload };
} catch (e) {
setError(e.message || t('post.unknownError'));
setError(describeApiError(e, t('post.unknownError')));
return null;
} finally {
setLoading(false);