fixed code
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API_URL } from "../config/authConstants";
|
||||
import { apiFetch } from "../api/apiClient";
|
||||
|
||||
@@ -19,6 +20,7 @@ import { apiFetch } from "../api/apiClient";
|
||||
* null — серверная ошибка (свойство error содержит текст)
|
||||
*/
|
||||
export function usePostMutation() {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
@@ -46,12 +48,12 @@ export function usePostMutation() {
|
||||
return { blocked: true, reason: body.reason || "" };
|
||||
}
|
||||
|
||||
throw new Error(body?.message || `Ошибка сервера: ${res.status}`);
|
||||
throw new Error(body?.message || t('post.serverError', { status: res.status }));
|
||||
}
|
||||
|
||||
return { data: await res.json() };
|
||||
} catch (e) {
|
||||
setError(e.message || "Неизвестная ошибка");
|
||||
setError(e.message || t('post.unknownError'));
|
||||
return null;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user