You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If input ip addr or netmask is invalid, it will throw error, then I must use nested try / catch to handle that.
It makes code complicated.
I suggest return a undefined / null value for calculate error. Like behavior of many JS native functions.
The text was updated successfully, but these errors were encountered:
I also feel if this is handled in the node-netmask as mentioned by @RainaWLK it would be great.
Alternatively, we could handle it on our end as mentioned in the code below, but we need to add another wrapper around Netmask to handle those cases.
function getNetMaskStatus({ipAddress, gateway, subnetMask}) {
// ipAddress and gateway cannot be the same
let netMaskStatus = {validIpAddress: false, validGateway: false, error: null};
try {
const block = new Netmask(ipAddress, subnetMask);
netMaskStatus.validIpAddress = true;
Log.info('block: ', block);
//ipAddress and gateway cannot be the same. gateway ip should be changed.
if (ipAddress === gateway) {
return netMaskStatus;
}
const gatewayisInSubnetRange = block.contains(gateway)
if (gatewayisInSubnetRange) {
netMaskStatus.validGateway = true;
return netMaskStatus;
}
else {
return netMaskStatus;
}
} catch (error) {
Log.error('Net mask Status: ',netMaskStatus);
Log.error('NetMask error: ', error);
netMaskStatus.error = error;
return netMaskStatus;
}
}
If input ip addr or netmask is invalid, it will throw error, then I must use nested try / catch to handle that.
It makes code complicated.
I suggest return a undefined / null value for calculate error. Like behavior of many JS native functions.
The text was updated successfully, but these errors were encountered: