فهرست منبع

[add] try catch

wenliming 2 سال پیش
والد
کامیت
b99de6418a
3فایلهای تغییر یافته به همراه129 افزوده شده و 63 حذف شده
  1. 33 16
      src/logic/background/denet.js
  2. 40 23
      src/logic/background/facebook.js
  3. 56 24
      src/logic/background/twitter.js

+ 33 - 16
src/logic/background/denet.js

@@ -1,25 +1,42 @@
 import { getChromeStorage } from '@/uilts/chromeExtension.js'
 import { payAchNoticeUrl } from '@/http/configAPI'
+import Report from "@/log-center/log"
 
 export const closeAchPayNoticeHandler = async () => {
-    let res = await getCurrentTab();
-    if(res.url.startsWith(payAchNoticeUrl)) {
-        chrome.tabs.remove(
-            res.id, () => {
-                getChromeStorage('achPayInfo', (result) => {
-                    let {tab} = result || {};
-                    chrome.storage.local.remove("achPayInfo");
-                    if(tab) {
-                        chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab.index })
-                    }
-                })
-            }
-        )
+    try{
+        let res = await getCurrentTab();
+        if(res.url.startsWith(payAchNoticeUrl)) {
+            chrome.tabs.remove(
+                res.id, () => {
+                    getChromeStorage('achPayInfo', (result) => {
+                        let {tab} = result || {};
+                        chrome.storage.local.remove("achPayInfo");
+                        if(tab) {
+                            chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab.index })
+                        }
+                    })
+                }
+            )
+        }
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'closeAchPayNoticeHandler',
+            errMsg: error.message
+        })
     }
 }
 
 const getCurrentTab = async () => {
-    let queryOptions = { active: true, lastFocusedWindow: true };
-    let [tab] = await chrome.tabs.query(queryOptions);
-    return tab || {};
+    try{
+        let queryOptions = { active: true, lastFocusedWindow: true };
+        let [tab] = await chrome.tabs.query(queryOptions);
+        return tab || {};
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'getCurrentTab',
+            errMsg: error.message
+        })
+    }
 }

+ 40 - 23
src/logic/background/facebook.js

@@ -1,36 +1,53 @@
 import { fetchAddFinishEvent } from '@/logic/background/fetch/facebook'
+import Report from "@/log-center/log"
 
 /**
  * facebook分享成功逻辑
  */
 export function facebookShareSuccess(params, sender) {
-    let {data} = params;
-    let {id} = sender.tab || {};
-    chrome.tabs.remove(id);
+    try{
+        let {data} = params;
+        let {id} = sender.tab || {};
+        chrome.tabs.remove(id);
 
-    fetchAddFinishEvent({
-        eventType: data.type,
-        luckdropId: data.taskLuckdropId
-    }).then(res => {
-        if (res.code == 0) {
-            setTimeout(() => {
-                sendActivetabMessage({
-                    actionType: 'BG_FACEBOOK_SHARE_SUCCESS',
-                    data: data
-                });
-            })
-        }
-    })
+        fetchAddFinishEvent({
+            eventType: data.type,
+            luckdropId: data.taskLuckdropId
+        }).then(res => {
+            if (res.code == 0) {
+                setTimeout(() => {
+                    sendActivetabMessage({
+                        actionType: 'BG_FACEBOOK_SHARE_SUCCESS',
+                        data: data
+                    });
+                })
+            }
+        })
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'facebookShareSuccess',
+            errMsg: error.message
+        })
+    }
 }
 
 
 function sendActivetabMessage(message = {}) {
-    chrome.tabs.query({
-        active: true,
-        currentWindow: true
-    }, (tabs) => {
-        chrome.tabs.sendMessage(tabs[0].id, message, res => {
-            console.log(res)
+    try{
+        chrome.tabs.query({
+            active: true,
+            currentWindow: true
+        }, (tabs) => {
+            chrome.tabs.sendMessage(tabs[0].id, message, res => {
+                console.log(res)
+            })
+        })
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'sendActivetabMessage',
+            errMsg: error.message
         })
-    })
+    }
 }

+ 56 - 24
src/logic/background/twitter.js

@@ -473,42 +473,74 @@ function createAlarm() {
 }
 
 export function getMessageInfo() {
-    fetchAllMessageInfo().then(res => {
-        if (res.code == 0) {
-            let { unReadCountTotal = 0 } = res.data;
-            if (unReadCountTotal > 0) {
-                let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal + '';
-                setBadgeInfo({ data: { text } });
-            } else {
-                hideBadge();
+    try {
+        fetchAllMessageInfo().then(res => {
+            if (res.code == 0) {
+                let { unReadCountTotal = 0 } = res.data;
+                if (unReadCountTotal > 0) {
+                    let text = unReadCountTotal > 99 ? '99+' : unReadCountTotal + '';
+                    setBadgeInfo({ data: { text } });
+                } else {
+                    hideBadge();
+                }
             }
-        }
-    })
+        })
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'getMessageInfo',
+            errMsg: error.message
+        })
+    }
 }
 
 export function readTaskAllMsg({ msgType }, cb) {
-    fetchReadTaskAllMsg({
-        msgType // 1:任务红包 2:钱包明细
-    }).then(res => {
-        if (res.code == 0) {
-            cb && cb();
-        }
-    });
+    try{
+        fetchReadTaskAllMsg({
+            msgType // 1:任务红包 2:钱包明细
+        }).then(res => {
+            if (res.code == 0) {
+                cb && cb();
+            }
+        });
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'readTaskAllMsg',
+            errMsg: error.message
+        })
+    }
 }
 
 export const onDisconnectHandler = (port) => {
-    if (port.name === "popup" || port.name === "popup_transactions") {
-        let msgType = port.name === "popup" ? 1 : 2;
-        readTaskAllMsg({ msgType }, () => {
-            getMessageInfo();
+    try{
+        if (port.name === "popup" || port.name === "popup_transactions") {
+            let msgType = port.name === "popup" ? 1 : 2;
+            readTaskAllMsg({ msgType }, () => {
+                getMessageInfo();
+            })
+        }
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'onDisconnectHandler',
+            errMsg: error.message
         })
     }
 }
 
 export const injectExtensionPopup = (tab) => {
-    sendActivetabMessage({
-        actionType: 'BG_INJECT_EXTENSION_POPUP'
-    });
+    try{
+        sendActivetabMessage({
+            actionType: 'BG_INJECT_EXTENSION_POPUP'
+        });
+    } catch (error) {
+        Report.reportLog({
+            objectType: Report.objectType.background_function_catch,
+            funcName: 'injectExtensionPopup',
+            errMsg: error.message
+        })
+    }
 }
 
 export const setPopupConfig = (activeInfo) => {