Browse Source

feat: toggle error if element doesn't exist on the element exist block

Ahmad Kholid 3 years ago
parent
commit
47683acdaa

+ 13 - 1
src/background/workflow-engine/blocks-handler/handler-element-exists.js

@@ -4,9 +4,21 @@ function elementExists(block) {
   return new Promise((resolve, reject) => {
     this._sendMessageToTab(block)
       .then((data) => {
+        const nextBlockId = getBlockConnection(block, data ? 1 : 2);
+
+        if (!data && block.data.throwError) {
+          const error = new Error('element-not-found');
+          error.nextBlockId = nextBlockId;
+          error.data = { selector: block.data.selector };
+
+          reject(error);
+
+          return;
+        }
+
         resolve({
           data,
-          nextBlockId: getBlockConnection(block, data ? 1 : 2),
+          nextBlockId,
         });
       })
       .catch((error) => {

+ 8 - 0
src/components/newtab/workflow/edit/EditElementExists.vue

@@ -35,6 +35,14 @@
       min="200"
       @change="updateData({ timeout: +$event })"
     />
+    <label class="flex items-center mt-4">
+      <ui-switch
+        :model-value="data.throwError"
+        class="mr-2"
+        @change="updateData({ throwError: $event })"
+      />
+      <span>{{ t('workflow.blocks.element-exists.throwError') }}</span>
+    </label>
   </div>
 </template>
 <script setup>

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

@@ -344,6 +344,7 @@
         "description": "Check if an element is exists",
         "selector": "Element selector",
         "fallbackTitle": "Execute when element doesn't exists",
+        "throwError": "Throw an error if doesn't exist",
         "tryFor": {
           "title": "How many times to try to check if element exist",
           "label": "Try for"

+ 1 - 0
src/utils/shared.js

@@ -548,6 +548,7 @@ export const tasks = {
       tryCount: 1,
       timeout: 500,
       markEl: false,
+      throwError: false,
     },
   },
   webhook: {