Skip to content

Commit

Permalink
Improved log out when running on device without network connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 21, 2020
1 parent d3615dd commit d97e122
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export declare interface NetworkManager {
export class NetworkManager extends EventEmitter {

private static readonly SPACE_PATTERN = /\s+/g;
private static readonly NOTHING_FOUND_MESSAGE = "no interfaces found";

private static readonly POLLING_TIME = 15 * 1000; // 15 seconds

Expand Down Expand Up @@ -451,7 +452,15 @@ export class NetworkManager extends EventEmitter {
return Promise.reject(new Error("unsupported platform!"));
}

const names = await promise;
let names: InterfaceName[];
try {
names = await promise;
} catch (error) {
if (error.message !== NetworkManager.NOTHING_FOUND_MESSAGE) {
throw error;
}
names = [];
}
const loopback = NetworkManager.getLoopbackInterface();

if (!names.includes(loopback)) {
Expand Down Expand Up @@ -534,7 +543,7 @@ export class NetworkManager extends EventEmitter {
if (names.length) {
resolve(names);
} else {
reject(new Error("WINDOWS: No interfaces were found!"));
reject(new Error(NetworkManager.NOTHING_FOUND_MESSAGE));
}
});
});
Expand Down Expand Up @@ -592,7 +601,7 @@ export class NetworkManager extends EventEmitter {
if (names.length) {
resolve(names);
} else {
reject(new Error("DARWIN: No interfaces were found!"));
reject(new Error(NetworkManager.NOTHING_FOUND_MESSAGE));
}
});
});
Expand Down Expand Up @@ -648,7 +657,7 @@ export class NetworkManager extends EventEmitter {
if (names.length) {
resolve(names);
} else {
reject(new Error("LINUX: No interfaces were found!"));
reject(new Error(NetworkManager.NOTHING_FOUND_MESSAGE));
}
});
});
Expand Down Expand Up @@ -682,7 +691,7 @@ export class NetworkManager extends EventEmitter {
if (names.length) {
resolve(names);
} else {
reject(new Error("FreeBSD: No interfaces were found!"));
reject(new Error(NetworkManager.NOTHING_FOUND_MESSAGE));
}
});
});
Expand Down Expand Up @@ -716,7 +725,7 @@ export class NetworkManager extends EventEmitter {
if (names.length) {
resolve(names);
} else {
reject(new Error(os.platform().toUpperCase() + ": No interfaces were found!"));
reject(new Error(NetworkManager.NOTHING_FOUND_MESSAGE));
}
});
});
Expand Down

0 comments on commit d97e122

Please sign in to comment.