Browse Source

feat: 加入try catch捕抓请求ip地址失败的情况

lanjianrong 4 years ago
parent
commit
29deca3e86
1 changed files with 14 additions and 9 deletions
  1. 14 9
      app/service/login_logging.js

+ 14 - 9
app/service/login_logging.js

@@ -64,15 +64,20 @@ module.exports = app => {
          * @return {String} 详细地址
          * @return {String} 详细地址
          */
          */
         async getIpInfoFromApi(a_ip = '') {
         async getIpInfoFromApi(a_ip = '') {
-            if (!a_ip) return '';
-            if (a_ip === '127.0.0.1' || a_ip === '::1' || a_ip.indexOf('192.168') !== -1) return '服务器本机访问';
-            const { ip = '', region = '', city = '', isp = '' } = await this.sendRequest(a_ip);
-            let address = '';
-            region && (address += region + '省');
-            city && (address += city + '市 ');
-            isp && (address += isp + ' ');
-            ip && (address += `(${ip})`);
-            return address;
+            try {
+                if (!a_ip) return '';
+                if (a_ip === '127.0.0.1' || a_ip === '::1' || a_ip.indexOf('192.168') !== -1) return '服务器本机访问';
+                const { ip = '', region = '', city = '', isp = '' } = await this.sendRequest(a_ip);
+                let address = '';
+                region && (address += region + '省');
+                city && (address += city + '市 ');
+                isp && (address += isp + ' ');
+                ip && (address += `(${ip})`);
+                return address;
+            } catch (error) {
+                return '';
+            }
+
         }
         }
 
 
         /**
         /**