diff --git a/packages/app-form-builder/src/components/Form/functions/getClientIp.ts b/packages/app-form-builder/src/components/Form/functions/getClientIp.ts index c199bc122a3..f7b433b7f40 100644 --- a/packages/app-form-builder/src/components/Form/functions/getClientIp.ts +++ b/packages/app-form-builder/src/components/Form/functions/getClientIp.ts @@ -1,16 +1,22 @@ export default (): Promise => { - return new Promise((resolve: (value: string) => void, reject: (error: string) => void) => { - const xhr = new window.XMLHttpRequest(); - xhr.open("GET", "https://api.ipify.org/?format=json", true); - xhr.setRequestHeader("Content-Type", "application/json"); - xhr.send(); - xhr.onload = function () { - try { + return new Promise((resolve: (value: string) => void) => { + try { + const xhr = new window.XMLHttpRequest(); + xhr.open("GET", "https://api.ipify.org/?format=json", true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(); + xhr.onload = function () { const response = JSON.parse(this.responseText); resolve(response.ip); - } catch (e) { - reject(""); - } - }; + }; + xhr.onabort = function () { + resolve("0.0.0.0"); + }; + xhr.onerror = function () { + resolve("0.0.0.0"); + }; + } catch (e) { + resolve("0.0.0.0"); + } }); };