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:
parent
17fd4f1512
commit
b502332076
|
|
@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -336,7 +336,7 @@ function* executeTriggerRequestSaga(
|
||||||
// a success: false is sent to reject the promise
|
// a success: false is sent to reject the promise
|
||||||
|
|
||||||
// @ts-expect-error: reason is of type string
|
// @ts-expect-error: reason is of type string
|
||||||
responsePayload.data.reason = error;
|
responsePayload.data.reason = { message: error.message };
|
||||||
responsePayload.success = false;
|
responsePayload.success = false;
|
||||||
}
|
}
|
||||||
responseChannel.put({
|
responseChannel.put({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user