From 5d7f68a03199653e40128c3b2f78ea77ff626b60 Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Thu, 25 Nov 2021 15:28:04 +0530 Subject: [PATCH] fix: Mute action execution errors when error callback is present (#9366) --- .../ActionExecution/Error_handling_spec.js | 65 +++++++++++++++++++ .../ActionExecution/ActionExecutionSagas.ts | 1 - .../sagas/ActionExecution/PluginActionSaga.ts | 3 - .../src/sagas/ActionExecution/errorUtils.ts | 10 +-- 4 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/ActionExecution/Error_handling_spec.js diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/ActionExecution/Error_handling_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/ActionExecution/Error_handling_spec.js new file mode 100644 index 0000000000..9d03a21d70 --- /dev/null +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/ActionExecution/Error_handling_spec.js @@ -0,0 +1,65 @@ +const commonlocators = require("../../../../locators/commonlocators.json"); +const dsl = require("../../../../fixtures/buttonApiDsl.json"); +const widgetsPage = require("../../../../locators/Widgets.json"); +const publishPage = require("../../../../locators/publishWidgetspage.json"); + +describe("Test Create Api and Bind to Table widget", function() { + before(() => { + cy.addDsl(dsl); + }); + + it("Test_Add users api and execute api", function() { + cy.createAndFillApi(this.data.userApi, "/random"); + cy.RunAPI(); + }); + + it("Call the api without error handling", () => { + cy.SearchEntityandOpen("Button1"); + cy.get(widgetsPage.toggleOnClick) + .invoke("attr", "class") + .then((classes) => { + if (classes.includes("is-active")) { + cy.get(widgetsPage.toggleOnClick).click(); + } + }); + cy.get(widgetsPage.toggleOnClick).click(); + + cy.get(".t--property-control-onclick").then(($el) => { + cy.updateCodeInput($el, "{{Api1.run()}}"); + }); + + cy.PublishtheApp(); + + cy.get(publishPage.buttonWidget).click(); + cy.wait("@postExecute").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + + cy.get(commonlocators.toastAction) + .should("have.length", 1) + .should("contain.text", "failed to execute"); + + cy.get(publishPage.backToEditor).click({ force: true }); + }); + + it("Call the api with error handling", () => { + cy.SearchEntityandOpen("Button1"); + + cy.get(".t--property-control-onclick").then(($el) => { + cy.updateCodeInput($el, "{{Api1.run(() => {}, () => {})}}"); + }); + + cy.PublishtheApp(); + + cy.get(publishPage.buttonWidget).click(); + cy.wait("@postExecute").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + + cy.get(commonlocators.toastAction).should("not.exist"); + }); +}); diff --git a/app/client/src/sagas/ActionExecution/ActionExecutionSagas.ts b/app/client/src/sagas/ActionExecution/ActionExecutionSagas.ts index faa468b77d..bbb92510cf 100644 --- a/app/client/src/sagas/ActionExecution/ActionExecutionSagas.ts +++ b/app/client/src/sagas/ActionExecution/ActionExecutionSagas.ts @@ -66,7 +66,6 @@ export function* executeActionTriggers( executePluginActionTriggerSaga, trigger.payload, eventType, - triggerMeta, ); break; case ActionTriggerType.CLEAR_PLUGIN_ACTION: diff --git a/app/client/src/sagas/ActionExecution/PluginActionSaga.ts b/app/client/src/sagas/ActionExecution/PluginActionSaga.ts index 56ff16bbf1..3ef1f12aa2 100644 --- a/app/client/src/sagas/ActionExecution/PluginActionSaga.ts +++ b/app/client/src/sagas/ActionExecution/PluginActionSaga.ts @@ -86,7 +86,6 @@ import { RunPluginActionDescription } from "entities/DataTree/actionTriggers"; import { APP_MODE } from "entities/App"; import { FileDataTypes } from "widgets/constants"; import { hideDebuggerErrors } from "actions/debuggerActions"; -import { TriggerMeta } from "sagas/ActionExecution/ActionExecutionSagas"; import { PluginTriggerFailureError, PluginActionExecutionError, @@ -243,7 +242,6 @@ function* confirmRunActionSaga() { export default function* executePluginActionTriggerSaga( pluginAction: RunPluginActionDescription["payload"], eventType: EventType, - triggerMeta: TriggerMeta, ) { const { actionId, params } = pluginAction; PerformanceTracker.startAsyncTracking( @@ -310,7 +308,6 @@ export default function* executePluginActionTriggerSaga( throw new PluginTriggerFailureError( createMessage(ERROR_PLUGIN_ACTION_EXECUTE, action.name), [payload.body, params], - triggerMeta, ); } else { AppsmithConsole.info({ diff --git a/app/client/src/sagas/ActionExecution/errorUtils.ts b/app/client/src/sagas/ActionExecution/errorUtils.ts index 8fd3982f17..cc57d4ca9c 100644 --- a/app/client/src/sagas/ActionExecution/errorUtils.ts +++ b/app/client/src/sagas/ActionExecution/errorUtils.ts @@ -58,15 +58,11 @@ export const logActionExecutionError = ( }); }; -export class PluginTriggerFailureError extends TriggerFailureError { +export class PluginTriggerFailureError extends Error { responseData: unknown[] = []; - constructor( - reason: string, - responseData: unknown[], - triggerMeta: TriggerMeta, - ) { - super(reason, triggerMeta); + constructor(reason: string, responseData: unknown[]) { + super(reason); this.responseData = responseData; } }