fix(api): показывать ошибки опроса в каталоге BGP
This commit is contained in:
1 parent
f9cfb4e532
commit
85e701960e
6 files changed
+114
-28
No files matched your search
@@ -0,0 +1,17 @@
|
||||
export async function pollBgpCatalog<S extends { id: number; name: string }, T extends { id: string; serverId: number }>(
|
||||
devices: readonly S[], read: (device: S) => Promise<T[]>,
|
||||
): Promise<{ sessions: T[]; failures: Array<{ serverId: number; serverName: string; error: string }> }> {
|
||||
const results = await Promise.all(devices.map(async device => {
|
||||
try {
|
||||
const sessions = await read(device)
|
||||
if (!Array.isArray(sessions) || sessions.some(s => s.serverId !== device.id || typeof s.id !== 'string' || !s.id.trim())) {
|
||||
throw new Error('Некорректный контекст BGP-каталога')
|
||||
}
|
||||
if (new Set(sessions.map(s => s.id)).size !== sessions.length) throw new Error('Повторяющиеся ID BGP-сессий')
|
||||
return { sessions, failures: [] }
|
||||
} catch (error) {
|
||||
return { sessions: [], failures: [{ serverId: device.id, serverName: device.name, error: error instanceof Error ? error.message : 'Ошибка опроса BGP' }] }
|
||||
}
|
||||
}))
|
||||
return { sessions: results.flatMap(r => r.sessions), failures: results.flatMap(r => r.failures) }
|
||||
}
|
||||
Reference in new issue
Block a user