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
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m55s
This commit is contained in:
@@ -2225,22 +2225,41 @@ function NetworkConfigManager() {
|
||||
const handleApplyMikrotikViaApi = async (dryRunOverride = null) => {
|
||||
if (!applyServerId) return;
|
||||
const useDryRun = dryRunOverride !== null ? dryRunOverride : applyDryRun;
|
||||
|
||||
setApplyLoading(true);
|
||||
if (dryRunOverride !== null) setApplyResult(null);
|
||||
|
||||
try {
|
||||
const { data } = await api.post('/mikrotik/apply', {
|
||||
serverId: applyServerId,
|
||||
type: 'all',
|
||||
dryRun: useDryRun,
|
||||
const response = await fetch('/api/mikrotik/apply', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'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);
|
||||
|
||||
if (data.ok && !useDryRun) {
|
||||
notify.success(`Применено: создано ${data.summary?.created || 0}, обновлено ${data.summary?.updated || 0}, пропущено ${data.summary?.skipped || 0}`);
|
||||
}
|
||||
} catch (error) {
|
||||
setApplyResult({
|
||||
ok: false,
|
||||
error: error.response?.data?.error || error.message || 'Ошибка применения',
|
||||
error: error.message || 'Ошибка применения',
|
||||
});
|
||||
notify.error('Не удалось применить конфигурацию по API');
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user