浏览代码

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

lanjianrong 4 年之前
父节点
当前提交
29deca3e86
共有 1 个文件被更改,包括 14 次插入9 次删除
  1. 14 9
      app/service/login_logging.js

+ 14 - 9
app/service/login_logging.js

@@ -64,15 +64,20 @@ module.exports = app => {
          * @return {String} 详细地址
          */
         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 '';
+            }
+
         }
 
         /**