From b502332076d93500b7bfe09fcbd262a2abdf90b4 Mon Sep 17 00:00:00 2001 From: Rimil Dey Date: Tue, 23 Aug 2022 11:32:31 +0530 Subject: [PATCH] fix: catch block not working in firefox and safari for async functions (#15376) * Add error.message only to data.reason, since the call stack being sent to responsePayload is different for different browsers. This fix ensures a consistent behaviour across all browsers * Add integration tests * Update test to typescript * Fix error message * Use new error instead of message object * Code review fix * Add else block to catch unknown errors * Update tests * Get back to original solution - error solution not working in safari --- .../ClientSideTests/BugTests/Bug15372_spec.ts | 29 +++++++++++++++++++ app/client/src/sagas/EvaluationsSaga.ts | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/BugTests/Bug15372_spec.ts diff --git a/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/BugTests/Bug15372_spec.ts b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/BugTests/Bug15372_spec.ts new file mode 100644 index 0000000000..f50bc243bb --- /dev/null +++ b/app/client/cypress/integration/Smoke_TestSuite/ClientSideTests/BugTests/Bug15372_spec.ts @@ -0,0 +1,29 @@ +import { ObjectsRegistry } from "../../../../support/Objects/Registry"; + +const { + AggregateHelper: agHelper, + ApiPage: apiPage, + JSEditor: jsEditor, +} = ObjectsRegistry; + +describe("[Bug]: Catch block was not triggering in Safari/firefox", () => { + it("1. Triggers the catch block when the API hits a 404", () => { + apiPage.CreateAndFillApi("https://swapi.dev/api/people/18261826", "Api1"); + cy.wait(3000); + + jsEditor.CreateJSObject( + `export default { + fun: async () => { + return await Api1.run().catch((e) => showAlert("404 hit : " + e.message)); + } + }`, + { + paste: true, + completeReplace: true, + toRun: true, + shouldCreateNewJSObj: true, + }, + ); + agHelper.WaitUntilToastDisappear("404 hit : Api1 failed to execute"); + }); +}); diff --git a/app/client/src/sagas/EvaluationsSaga.ts b/app/client/src/sagas/EvaluationsSaga.ts index a8b7d07232..0624172682 100644 --- a/app/client/src/sagas/EvaluationsSaga.ts +++ b/app/client/src/sagas/EvaluationsSaga.ts @@ -336,7 +336,7 @@ function* executeTriggerRequestSaga( // a success: false is sent to reject the promise // @ts-expect-error: reason is of type string - responsePayload.data.reason = error; + responsePayload.data.reason = { message: error.message }; responsePayload.success = false; } responseChannel.put({