Skip to content

Commit

Permalink
fix(app-form-builder): handle IP resolution exceptions (#2919)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jan 3, 2023
1 parent 30bbf3f commit f1be107
Showing 1 changed file with 17 additions and 11 deletions.
@@ -1,16 +1,22 @@
export default (): Promise<string> => {
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");
}
});
};

0 comments on commit f1be107

Please sign in to comment.