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:
@@ -2,6 +2,7 @@ import { useState, useCallback, useRef } from "react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API_URL } from "../config/authConstants";
|
||||
import { apiFetch } from "../api/apiClient";
|
||||
import { readApiError } from "../api/apiErrors";
|
||||
import { cachePostsFromChats, setPostForChat } from "../stores/chatPostStore";
|
||||
import { useUnread } from "../context/UnreadContext";
|
||||
|
||||
@@ -66,13 +67,16 @@ export function useChats() {
|
||||
body: JSON.stringify({ content }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
await logChatError("startChat", res);
|
||||
throw new Error(t('chats.sendError'));
|
||||
// ApiError несёт статус и текст сервера: ChatPage покажет «слишком
|
||||
// много попыток» на 429 и причину отказа на 400
|
||||
const err = await readApiError(res);
|
||||
console.warn("startChat failed:", err.status, err.serverMessage);
|
||||
throw err;
|
||||
}
|
||||
const chat = await res.json();
|
||||
cacheChatPost(chat, postInfo);
|
||||
return chat;
|
||||
}, [t]);
|
||||
}, []);
|
||||
|
||||
const fetchMessages = useCallback(async (chatId) => {
|
||||
const res = await apiFetch(`${API_URL}/api/v1/chats/${chatId}/messages`);
|
||||
|
||||
Reference in New Issue
Block a user