diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js index 44fd014..5260efc 100644 --- a/server/src/lib/wifiDevices.js +++ b/server/src/lib/wifiDevices.js @@ -95,11 +95,37 @@ async function updateDB(onlineDevices) { } }) } catch (e) { - logError({ - tags: ['wifiDevices'], - message: `Error trying to upsert device with mac "${device.mac}"`, - data: { error: e, device } - }) + // If is a binding problem, probably the device has an user outside of AD, so save it anyway... + if (e.code == 'P2016') + try { + await forceUserDisconnect(device.mac) + await prisma.wifiDevice.upsert({ + where: { mac: device.mac }, + create: { + ...device, + hostname, + firstSeen: device.firstSeen || new Date(), + user: undefined + }, + update: { + ...device, + hostname, + user: undefined + } + }) + } catch (e) { + logError({ + tags: ['wifiDevices'], + message: `Error trying to upsert device with mac "${device.mac}". It has an user, but not in AD. And fails anyway...`, + data: { error: e, device } + }) + } + else + logError({ + tags: ['wifiDevices'], + message: `Error trying to upsert device with mac "${device.mac}"`, + data: { error: e, device } + }) } } }