فهرست منبع

feat: add error handler in active tab block

Ahmad Kholid 3 سال پیش
والد
کامیت
416fb4dc1b
2فایلهای تغییر یافته به همراه12 افزوده شده و 5 حذف شده
  1. 11 5
      src/background/workflow-engine/blocks-handler/handler-active-tab.js
  2. 1 0
      src/locales/en/newtab.json

+ 11 - 5
src/background/workflow-engine/blocks-handler/handler-active-tab.js

@@ -22,6 +22,13 @@ async function activeTab(block) {
       currentWindow: true,
     });
 
+    if (!tab?.url.startsWith('http')) {
+      const error = new Error('invalid-active-tab');
+      error.data = { url: tab.url };
+
+      throw error;
+    }
+
     this.frames = await executeContentScript(tab.id);
 
     this.frameId = 0;
@@ -32,11 +39,10 @@ async function activeTab(block) {
     return data;
   } catch (error) {
     console.error(error);
-    return {
-      data: '',
-      message: error.message || error,
-      nextBlockId,
-    };
+    error.nextBlockId = nextBlockId;
+    error.data = error.data || {};
+
+    throw error;
   }
 }
 

+ 1 - 0
src/locales/en/newtab.json

@@ -92,6 +92,7 @@
       "invalid-body": "Content body is not valid",
       "workflow-disabled": "Workflow is disabled",
       "selector-empty": "Element selector is empty",
+      "invalid-active-tab": "\"{url}\" is invalid URL",
       "empty-workflow": "You must select a workflow first",
       "active-tab-removed": "Workflow active tab is removed",
       "stop-timeout": "Workflow is stopped because of timeout",