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
This commit is contained in:
Rimil Dey 2022-08-23 11:32:31 +05:30 committed by GitHub
parent 17fd4f1512
commit b502332076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -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");
});
});

View File

@ -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({