From 60620177a992874e55906a40f7bba7186441817f Mon Sep 17 00:00:00 2001 From: Lightemerald Date: Mon, 26 Jun 2023 09:30:30 +0200 Subject: [PATCH] Fix --- index.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index a0c6b09..88adeb3 100644 --- a/index.js +++ b/index.js @@ -70,16 +70,22 @@ async function vpnConnect(vpnName) { await sleep(1000); } else { - const response = await fetch('https://api.ipify.org/?format=json', { - method: 'GET', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, - }); - const res = await response.json(); - const ip = res.ip; - await consoleLog(`[${host}] VPN connection successfully established to ${vpnName} (IP: ${ip}).`, 'info'); + try { + const response = await fetch('https://api.ipify.org/?format=json', { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + }); + const res = await response.json(); + const ip = res.ip; + await consoleLog(`[${host}] VPN connection successfully established to ${vpnName} (IP: ${ip}).`, 'info'); + } + catch (err) { + const ip = 'Unknown'; + await consoleLog(`[${host}] VPN connection successfully established to ${vpnName} (IP: ${ip}).`, 'info'); + } return 0; } }