refactor(NetworkConfigManager): update API call for applying MikroTik configuration to use fetch; improve error handling and response processing
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m55s

This commit is contained in:
2026-02-03 19:48:05 +07:00
parent 94314c383b
commit 3319f9c329
+24 -5
View File
@@ -2225,22 +2225,41 @@ function NetworkConfigManager() {
const handleApplyMikrotikViaApi = async (dryRunOverride = null) => { const handleApplyMikrotikViaApi = async (dryRunOverride = null) => {
if (!applyServerId) return; if (!applyServerId) return;
const useDryRun = dryRunOverride !== null ? dryRunOverride : applyDryRun; const useDryRun = dryRunOverride !== null ? dryRunOverride : applyDryRun;
setApplyLoading(true); setApplyLoading(true);
if (dryRunOverride !== null) setApplyResult(null); if (dryRunOverride !== null) setApplyResult(null);
try { try {
const { data } = await api.post('/mikrotik/apply', { const response = await fetch('/api/mikrotik/apply', {
serverId: applyServerId, method: 'POST',
type: 'all', headers: {
dryRun: useDryRun, 'Content-Type': 'application/json',
},
body: JSON.stringify({
serverId: applyServerId,
type: 'all',
dryRun: useDryRun,
}),
}); });
const data = await response.json().catch(() => ({}));
if (!response.ok || data.ok === false) {
const errorMessage = data.error || data.message || `HTTP ${response.status}`;
setApplyResult({ ok: false, error: errorMessage });
notify.error('Не удалось применить конфигурацию по API');
return;
}
setApplyResult(data); setApplyResult(data);
if (data.ok && !useDryRun) { if (data.ok && !useDryRun) {
notify.success(`Применено: создано ${data.summary?.created || 0}, обновлено ${data.summary?.updated || 0}, пропущено ${data.summary?.skipped || 0}`); notify.success(`Применено: создано ${data.summary?.created || 0}, обновлено ${data.summary?.updated || 0}, пропущено ${data.summary?.skipped || 0}`);
} }
} catch (error) { } catch (error) {
setApplyResult({ setApplyResult({
ok: false, ok: false,
error: error.response?.data?.error || error.message || 'Ошибка применения', error: error.message || 'Ошибка применения',
}); });
notify.error('Не удалось применить конфигурацию по API'); notify.error('Не удалось применить конфигурацию по API');
} finally { } finally {