PromucFlow_constructor/app/client/src/sagas/ErrorSagas.tsx

341 lines
9.2 KiB
TypeScript
Raw Normal View History

import { get } from "lodash";
import type { ReduxAction } from "ee/constants/ReduxActionConstants";
2019-09-27 16:05:33 +00:00
import {
ReduxActionTypes,
ReduxActionErrorTypes,
} from "ee/constants/ReduxActionConstants";
import log from "loglevel";
import history from "utils/history";
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com> ## Description This PR upgrades Prettier to v2 + enforces TypeScript’s [`import type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax where applicable. It’s submitted as a separate PR so we can merge it easily. As a part of this PR, we reformat the codebase heavily: - add `import type` everywhere where it’s required, and - re-format the code to account for Prettier 2’s breaking changes: https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes This PR is submitted against `release` to make sure all new code by team members will adhere to new formatting standards, and we’ll have fewer conflicts when merging `bundle-optimizations` into `release`. (I’ll merge `release` back into `bundle-optimizations` once this PR is merged.) ### Why is this needed? This PR is needed because, for the Lodash optimization from https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3, we need to use `import type`. Otherwise, `babel-plugin-lodash` complains that `LoDashStatic` is not a lodash function. However, just using `import type` in the current codebase will give you this: <img width="962" alt="Screenshot 2023-03-08 at 17 45 59" src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png"> That’s because Prettier 1 can’t parse `import type` at all. To parse it, we need to upgrade to Prettier 2. ### Why enforce `import type`? Apart from just enabling `import type` support, this PR enforces specifying `import type` everywhere it’s needed. (Developers will get immediate TypeScript and ESLint errors when they forget to do so.) I’m doing this because I believe `import type` improves DX and makes refactorings easier. Let’s say you had a few imports like below. Can you tell which of these imports will increase the bundle size? (Tip: it’s not all of them!) ```ts // app/client/src/workers/Linting/utils.ts import { Position } from "codemirror"; import { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` It’s pretty hard, right? What about now? ```ts // app/client/src/workers/Linting/utils.ts import type { Position } from "codemirror"; import type { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` Now, it’s clear that only `lodash` will be bundled. This helps developers to see which imports are problematic, but it _also_ helps with refactorings. Now, if you want to see where `codemirror` is bundled, you can just grep for `import \{.*\} from "codemirror"` – and you won’t get any type-only imports. This also helps (some) bundlers. Upon transpiling, TypeScript erases type-only imports completely. In some environment (not ours), this makes the bundle smaller, as the bundler doesn’t need to bundle type-only imports anymore. ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? This was tested to not break the build. ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
import type { ApiResponse } from "api/ApiResponses";
2023-04-05 08:39:00 +00:00
import { flushErrors, safeCrashApp } from "actions/errorActions";
import { AUTH_LOGIN_URL } from "constants/routes";
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com> ## Description This PR upgrades Prettier to v2 + enforces TypeScript’s [`import type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax where applicable. It’s submitted as a separate PR so we can merge it easily. As a part of this PR, we reformat the codebase heavily: - add `import type` everywhere where it’s required, and - re-format the code to account for Prettier 2’s breaking changes: https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes This PR is submitted against `release` to make sure all new code by team members will adhere to new formatting standards, and we’ll have fewer conflicts when merging `bundle-optimizations` into `release`. (I’ll merge `release` back into `bundle-optimizations` once this PR is merged.) ### Why is this needed? This PR is needed because, for the Lodash optimization from https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3, we need to use `import type`. Otherwise, `babel-plugin-lodash` complains that `LoDashStatic` is not a lodash function. However, just using `import type` in the current codebase will give you this: <img width="962" alt="Screenshot 2023-03-08 at 17 45 59" src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png"> That’s because Prettier 1 can’t parse `import type` at all. To parse it, we need to upgrade to Prettier 2. ### Why enforce `import type`? Apart from just enabling `import type` support, this PR enforces specifying `import type` everywhere it’s needed. (Developers will get immediate TypeScript and ESLint errors when they forget to do so.) I’m doing this because I believe `import type` improves DX and makes refactorings easier. Let’s say you had a few imports like below. Can you tell which of these imports will increase the bundle size? (Tip: it’s not all of them!) ```ts // app/client/src/workers/Linting/utils.ts import { Position } from "codemirror"; import { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` It’s pretty hard, right? What about now? ```ts // app/client/src/workers/Linting/utils.ts import type { Position } from "codemirror"; import type { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` Now, it’s clear that only `lodash` will be bundled. This helps developers to see which imports are problematic, but it _also_ helps with refactorings. Now, if you want to see where `codemirror` is bundled, you can just grep for `import \{.*\} from "codemirror"` – and you won’t get any type-only imports. This also helps (some) bundlers. Upon transpiling, TypeScript erases type-only imports completely. In some environment (not ours), this makes the bundle smaller, as the bundler doesn’t need to bundle type-only imports anymore. ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? This was tested to not break the build. ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
import type { User } from "constants/userConstants";
import { ERROR_CODES, SERVER_ERROR_CODES } from "ee/constants/ApiConstants";
import { getSafeCrash } from "selectors/errorSelectors";
import { getCurrentUser } from "selectors/usersSelectors";
import { ANONYMOUS_USERNAME } from "constants/userConstants";
import { put, takeLatest, call, select } from "redux-saga/effects";
import {
ERROR_401,
ERROR_403,
ERROR_500,
ERROR_0,
DEFAULT_ERROR_MESSAGE,
createMessage,
} from "ee/constants/messages";
import store from "store";
2019-09-27 16:05:33 +00:00
2021-06-23 15:42:07 +00:00
import * as Sentry from "@sentry/react";
import { axiosConnectionAbortedCode } from "ee/api/ApiUtils";
import { getLoginUrl } from "ee/utils/adminSettingsHelpers";
import type { PluginErrorDetails } from "api/ActionAPI";
feat: disabling the toast messages on view mode without debug flag (#23768) ## Description When the application is in published mode, this Pr offers the ability to disable the error toast. Only the toasts that the user initiated are displayed; all others are disabled and messages are logged in the console. When the view mode url has `debug=true` as one of the query params, then all the error toasts are visible. #### PR fixes following issue(s) Fixes #23605 Fixes #23603 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-09 13:58:45 +00:00
import showToast from "sagas/ToastSagas";
2021-06-23 15:42:07 +00:00
/**
* making with error message with action name
*
* @param action
*/
export const getDefaultActionError = (action: string) =>
`Incurred an error when ${action}`;
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2019-12-16 08:49:10 +00:00
export function* callAPI(apiCall: any, requestPayload: any) {
try {
const response: ApiResponse = yield call(apiCall, requestPayload);
return response;
2019-12-16 08:49:10 +00:00
} catch (error) {
return error;
2019-12-16 08:49:10 +00:00
}
}
/**
feat: URL Navigation for Widgets (#20202) ## Description Widget selection is driven by URL changes. This would fix browser navigation for users as they can use browser back/forward buttons to travel across older contexts on Appsmith. > Fixing browser URL navigation for widgets Fixes #19571 Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan > Add Testsmith [test cases](https://github.com/appsmithorg/TestSmith/issues/2171) links that relate to this PR ### Issues raised during DP testing - [X] When a selected widget is below viewport and user refreshes the page, then the widget property pane is open but the page does not navigate to the selected widget https://loom.com/share/09f1eda2f02d474981a0d48e4a6419ec - [ ] Drop 2 widgets one at a time > Delete both the widgets > Now click on back button of the browser > Observe the url it shows the widget id in the URL but the canvas remains empty https://loom.com/share/53cae28a5d224e67b783c8ccf53745f5 Dev Response: This issue is valid but not a major inconvenience. We will try to track it and see if it needed to be addressed. Many other web tools do not handle such cases - [X] Canvas scrolls down when all widgets are selected. https://loom.com/share/c8a68dadcdb040779abd3a73bde2b06c - [X] Widget is not getting highlighted when added from the API editor page. Please refer to the attached video:-https://jiju8jbmwa.vmaker.com/record/IkwiAqFgafK9dVmu ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [x] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2023-02-21 13:38:16 +00:00
* transform server errors to client error codes
*
* @param code
feat: URL Navigation for Widgets (#20202) ## Description Widget selection is driven by URL changes. This would fix browser navigation for users as they can use browser back/forward buttons to travel across older contexts on Appsmith. > Fixing browser URL navigation for widgets Fixes #19571 Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan > Add Testsmith [test cases](https://github.com/appsmithorg/TestSmith/issues/2171) links that relate to this PR ### Issues raised during DP testing - [X] When a selected widget is below viewport and user refreshes the page, then the widget property pane is open but the page does not navigate to the selected widget https://loom.com/share/09f1eda2f02d474981a0d48e4a6419ec - [ ] Drop 2 widgets one at a time > Delete both the widgets > Now click on back button of the browser > Observe the url it shows the widget id in the URL but the canvas remains empty https://loom.com/share/53cae28a5d224e67b783c8ccf53745f5 Dev Response: This issue is valid but not a major inconvenience. We will try to track it and see if it needed to be addressed. Many other web tools do not handle such cases - [X] Canvas scrolls down when all widgets are selected. https://loom.com/share/c8a68dadcdb040779abd3a73bde2b06c - [X] Widget is not getting highlighted when added from the API editor page. Please refer to the attached video:-https://jiju8jbmwa.vmaker.com/record/IkwiAqFgafK9dVmu ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [x] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2023-02-21 13:38:16 +00:00
* @param resourceType
*/
const getErrorMessage = (code: number, resourceType = "") => {
2019-12-16 08:49:10 +00:00
switch (code) {
case 401:
return createMessage(ERROR_401);
2019-12-16 08:49:10 +00:00
case 500:
return createMessage(ERROR_500);
case 403:
return createMessage(() =>
ERROR_403(resourceType, getCurrentUser(store.getState())?.email || ""),
);
case 0:
return createMessage(ERROR_0);
2019-12-16 08:49:10 +00:00
}
};
export class IncorrectBindingError extends Error {}
/**
* validates if response does have any errors
* @throws {Error}
* @param response
* @param show
feat: URL Navigation for Widgets (#20202) ## Description Widget selection is driven by URL changes. This would fix browser navigation for users as they can use browser back/forward buttons to travel across older contexts on Appsmith. > Fixing browser URL navigation for widgets Fixes #19571 Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan > Add Testsmith [test cases](https://github.com/appsmithorg/TestSmith/issues/2171) links that relate to this PR ### Issues raised during DP testing - [X] When a selected widget is below viewport and user refreshes the page, then the widget property pane is open but the page does not navigate to the selected widget https://loom.com/share/09f1eda2f02d474981a0d48e4a6419ec - [ ] Drop 2 widgets one at a time > Delete both the widgets > Now click on back button of the browser > Observe the url it shows the widget id in the URL but the canvas remains empty https://loom.com/share/53cae28a5d224e67b783c8ccf53745f5 Dev Response: This issue is valid but not a major inconvenience. We will try to track it and see if it needed to be addressed. Many other web tools do not handle such cases - [X] Canvas scrolls down when all widgets are selected. https://loom.com/share/c8a68dadcdb040779abd3a73bde2b06c - [X] Widget is not getting highlighted when added from the API editor page. Please refer to the attached video:-https://jiju8jbmwa.vmaker.com/record/IkwiAqFgafK9dVmu ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [x] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2023-02-21 13:38:16 +00:00
* @param logToSentry
*/
export function* validateResponse(
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: ApiResponse | any,
show = true,
logToSentry = false,
) {
if (!response) {
throw Error("");
}
// letting `apiFailureResponseInterceptor` handle it this case
if (response?.code === axiosConnectionAbortedCode) {
return false;
}
if (!response.responseMeta && !response.status) {
throw Error(getErrorMessage(0));
}
2019-12-16 08:49:10 +00:00
if (!response.responseMeta && response.status) {
throw Error(getErrorMessage(response.status, response.resourceType));
2019-12-16 08:49:10 +00:00
}
2019-09-27 16:05:33 +00:00
if (response.responseMeta.success) {
return true;
}
if (
feat: Error handling phase 1 (#20629) ## Description This PR updates the error logs - Establishing a consistent format for all error messages. - Revising error titles and details for improved understanding. - Compiling internal documentation of all error categories, subcategories, and error descriptions. Updated Error Interface: https://www.notion.so/appsmith/Error-Interface-for-Plugin-Execution-Error-7b3f5323ba4c40bfad281ae717ccf79b PRD: https://www.notion.so/appsmith/PRD-Error-Handling-Framework-4ac9747057fd4105a9d52cb8b42f4452?pvs=4#008e9c79ff3c484abf0250a5416cf052 >TL;DR Fixes # Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ### Test Plan ### Issues raised during DP testing ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --------- Co-authored-by: subrata <subrata@appsmith.com>
2023-02-18 12:55:46 +00:00
SERVER_ERROR_CODES.INCORRECT_BINDING_LIST_OF_WIDGET.includes(
response.responseMeta.error.code,
)
) {
throw new IncorrectBindingError(response.responseMeta.error.message);
}
yield put({
type: ReduxActionErrorTypes.API_ERROR,
payload: {
fix: throw exception-like object to sentry (#25445) ## Cause of issue The error passed to `Sentry.captureException ` was not an exception-like object. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/25397(https://github.com/appsmithorg/appsmith/issues/25397) #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-07-25 05:03:52 +00:00
error: new Error(response.responseMeta.error.message),
logToSentry,
show,
},
});
throw Error(response.responseMeta.error.message);
2019-09-27 16:05:33 +00:00
}
2019-12-16 08:49:10 +00:00
export function getResponseErrorMessage(response: ApiResponse) {
return response.responseMeta.error
? response.responseMeta.error.message
: undefined;
}
interface ClientDefinedErrorMetadata {
clientDefinedError: boolean;
statusCode: string;
message: string;
pluginErrorDetails: PluginErrorDetails;
}
export function extractClientDefinedErrorMetadata(
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
err: any,
): ClientDefinedErrorMetadata | undefined {
if (err?.clientDefinedError && err?.response) {
return {
clientDefinedError: err?.clientDefinedError,
statusCode: err?.statusCode,
message: err?.message,
pluginErrorDetails: err?.pluginErrorDetails,
};
} else {
return undefined;
}
}
export interface ErrorPayloadType {
code?: number | string;
message?: string;
crash?: boolean;
}
const ActionErrorDisplayMap: {
2019-10-07 13:19:29 +00:00
[key: string]: (error: ErrorPayloadType) => string;
} = {
2020-12-24 04:32:25 +00:00
[ReduxActionErrorTypes.API_ERROR]: (error) =>
get(error, "message", createMessage(DEFAULT_ERROR_MESSAGE)),
2019-10-07 13:11:18 +00:00
[ReduxActionErrorTypes.FETCH_PAGE_ERROR]: () =>
getDefaultActionError("fetching the page"),
2019-10-07 13:11:18 +00:00
[ReduxActionErrorTypes.SAVE_PAGE_ERROR]: () =>
getDefaultActionError("saving the page"),
2019-10-07 13:11:18 +00:00
};
const getErrorMessageFromActionType = (
type: string,
error: ErrorPayloadType,
): string => {
const actionErrorMessage = get(error, "message");
if (actionErrorMessage === undefined) {
if (type in ActionErrorDisplayMap) {
return ActionErrorDisplayMap[type](error);
}
return createMessage(DEFAULT_ERROR_MESSAGE);
}
return actionErrorMessage;
};
enum ErrorEffectTypes {
SHOW_ALERT = "SHOW_ALERT",
SAFE_CRASH = "SAFE_CRASH",
LOG_ERROR = "LOG_ERROR",
2021-06-23 15:42:07 +00:00
LOG_TO_SENTRY = "LOG_TO_SENTRY",
}
export interface ErrorActionPayload {
error: ErrorPayloadType;
show?: boolean;
crash?: boolean;
2021-06-23 15:42:07 +00:00
logToSentry?: boolean;
}
export function* errorSaga(errorAction: ReduxAction<ErrorActionPayload>) {
const effects = [ErrorEffectTypes.LOG_ERROR];
const { payload, type } = errorAction;
2021-06-23 15:42:07 +00:00
const { error, logToSentry, show = true } = payload || {};
const message = getErrorMessageFromActionType(type, error);
if (show) {
effects.push(ErrorEffectTypes.SHOW_ALERT);
}
if (error && error.crash) {
2023-03-30 11:20:26 +00:00
effects.push(ErrorEffectTypes.LOG_TO_SENTRY);
effects.push(ErrorEffectTypes.SAFE_CRASH);
}
2021-06-23 15:42:07 +00:00
if (error && logToSentry) {
effects.push(ErrorEffectTypes.LOG_TO_SENTRY);
}
for (const effect of effects) {
switch (effect) {
case ErrorEffectTypes.LOG_ERROR: {
logErrorSaga(errorAction);
break;
}
case ErrorEffectTypes.SHOW_ALERT: {
feat: disabling the toast messages on view mode without debug flag (#23768) ## Description When the application is in published mode, this Pr offers the ability to disable the error toast. Only the toasts that the user initiated are displayed; all others are disabled and messages are logged in the console. When the view mode url has `debug=true` as one of the query params, then all the error toasts are visible. #### PR fixes following issue(s) Fixes #23605 Fixes #23603 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [x] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-09 13:58:45 +00:00
// This is the toast that is rendered when any page load API fails.
yield call(showToast, message, { kind: "error" });
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((window as any).Cypress) {
if (message === "" || message === null) {
yield put(
safeCrashApp({
...error,
code: ERROR_CODES.CYPRESS_DEBUG,
}),
);
}
}
break;
}
case ErrorEffectTypes.SAFE_CRASH: {
2023-04-05 08:39:00 +00:00
yield put(safeCrashApp(error));
break;
}
2021-06-23 15:42:07 +00:00
case ErrorEffectTypes.LOG_TO_SENTRY: {
yield call(Sentry.captureException, error);
break;
}
}
2020-04-15 14:19:39 +00:00
}
2019-09-27 16:05:33 +00:00
yield put({
type: ReduxActionTypes.REPORT_ERROR,
payload: {
source: errorAction.type,
message,
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
stackTrace: (error as any)?.stack,
2019-09-27 16:05:33 +00:00
},
});
}
function logErrorSaga(action: ReduxAction<{ error: ErrorPayloadType }>) {
log.debug(`Error in action ${action.type}`);
if (action.payload) log.error(action.payload.error, action);
}
export function embedRedirectURL() {
const queryParams = new URLSearchParams(window.location.search);
const ssoTriggerQueryParam = queryParams.get("ssoTrigger");
const ssoLoginUrl = ssoTriggerQueryParam
? getLoginUrl(ssoTriggerQueryParam || "")
: null;
if (ssoLoginUrl) {
window.location.href = `${ssoLoginUrl}?redirectUrl=${encodeURIComponent(
window.location.href,
)}`;
} else {
window.location.href = `${AUTH_LOGIN_URL}?redirectUrl=${encodeURIComponent(
window.location.href,
)}`;
}
}
/**
* this saga do some logic before actually setting safeCrash to true
*/
2023-04-05 08:39:00 +00:00
function* safeCrashSagaRequest(action: ReduxAction<{ code?: ERROR_CODES }>) {
const user: User | undefined = yield select(getCurrentUser);
const code = get(action, "payload.code");
// if user is not logged and the error is "PAGE_NOT_FOUND",
// redirecting user to login page with redirecTo param
if (
get(user, "email") === ANONYMOUS_USERNAME &&
code === ERROR_CODES.PAGE_NOT_FOUND
) {
embedRedirectURL();
return false;
}
// if there is no action to be done, just calling the safe crash action
2023-04-05 08:39:00 +00:00
yield put(safeCrashApp({ code }));
}
/**
* flush errors and redirect users to a url
*
* @param action
*/
export function* flushErrorsAndRedirectSaga(
action: ReduxAction<{ url?: string }>,
) {
const safeCrash: boolean = yield select(getSafeCrash);
if (safeCrash) {
yield put(flushErrors());
}
2022-12-15 04:06:13 +00:00
if (!action.payload.url) return;
history.push(action.payload.url);
}
2019-09-27 16:05:33 +00:00
export default function* errorSagas() {
yield takeLatest(Object.values(ReduxActionErrorTypes), errorSaga);
yield takeLatest(
ReduxActionTypes.FLUSH_AND_REDIRECT,
flushErrorsAndRedirectSaga,
);
yield takeLatest(
ReduxActionTypes.SAFE_CRASH_APPSMITH_REQUEST,
safeCrashSagaRequest,
);
2019-09-27 16:05:33 +00:00
}