2021-09-23 07:21:57 +00:00
|
|
|
import { TriggerMeta } from "sagas/ActionExecution/ActionExecutionSagas";
|
|
|
|
|
import { TriggerSource } from "constants/AppsmithActionConstants/ActionConstants";
|
|
|
|
|
import { PropertyEvaluationErrorType } from "utils/DynamicBindingUtils";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
|
|
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
|
|
|
|
import { createMessage, DEBUGGER_TRIGGER_ERROR } from "constants/messages";
|
|
|
|
|
import { ENTITY_TYPE } from "entities/AppsmithConsole";
|
|
|
|
|
import { Toaster } from "components/ads/Toast";
|
|
|
|
|
import { Variant } from "components/ads/common";
|
|
|
|
|
import { ApiResponse } from "api/ApiResponses";
|
2021-10-14 11:04:43 +00:00
|
|
|
import { isString } from "lodash";
|
2021-09-23 07:21:57 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The base trigger error that also logs the errors in the debugger.
|
|
|
|
|
* Extend this error to make custom handling of errors
|
|
|
|
|
*/
|
|
|
|
|
export class TriggerFailureError extends Error {
|
|
|
|
|
error?: Error;
|
|
|
|
|
|
|
|
|
|
constructor(reason: string, triggerMeta: TriggerMeta, error?: Error) {
|
|
|
|
|
super(reason);
|
|
|
|
|
this.error = error;
|
|
|
|
|
const { source, triggerPropertyName } = triggerMeta;
|
|
|
|
|
const errorMessage = error?.message || reason;
|
|
|
|
|
|
|
|
|
|
logActionExecutionError(errorMessage, source, triggerPropertyName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const logActionExecutionError = (
|
|
|
|
|
errorMessage: string,
|
|
|
|
|
source?: TriggerSource,
|
|
|
|
|
triggerPropertyName?: string,
|
|
|
|
|
errorType?: PropertyEvaluationErrorType,
|
|
|
|
|
) => {
|
|
|
|
|
AppsmithConsole.addError({
|
|
|
|
|
id: `${source?.id}-${triggerPropertyName}`,
|
|
|
|
|
logType: LOG_TYPE.TRIGGER_EVAL_ERROR,
|
|
|
|
|
text: createMessage(DEBUGGER_TRIGGER_ERROR, triggerPropertyName),
|
|
|
|
|
source: {
|
|
|
|
|
type: ENTITY_TYPE.WIDGET,
|
|
|
|
|
id: source?.id ?? "",
|
|
|
|
|
name: source?.name ?? "",
|
|
|
|
|
propertyPath: triggerPropertyName,
|
|
|
|
|
},
|
|
|
|
|
messages: [
|
|
|
|
|
{
|
|
|
|
|
type: errorType,
|
|
|
|
|
message: errorMessage,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Toaster.show({
|
|
|
|
|
text: errorMessage,
|
|
|
|
|
variant: Variant.danger,
|
|
|
|
|
showDebugButton: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-25 09:58:04 +00:00
|
|
|
export class PluginTriggerFailureError extends Error {
|
2021-09-23 07:21:57 +00:00
|
|
|
responseData: unknown[] = [];
|
|
|
|
|
|
2021-11-25 09:58:04 +00:00
|
|
|
constructor(reason: string, responseData: unknown[]) {
|
|
|
|
|
super(reason);
|
2021-09-23 07:21:57 +00:00
|
|
|
this.responseData = responseData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Thrown when action execution fails for some reason
|
|
|
|
|
* */
|
|
|
|
|
export class PluginActionExecutionError extends Error {
|
|
|
|
|
response?: ApiResponse;
|
|
|
|
|
userCancelled: boolean;
|
|
|
|
|
|
|
|
|
|
constructor(message: string, userCancelled: boolean, response?: ApiResponse) {
|
|
|
|
|
super(message);
|
|
|
|
|
this.name = "PluginActionExecutionError";
|
|
|
|
|
this.userCancelled = userCancelled;
|
|
|
|
|
this.response = response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The user cancelled the run of this action in a confirmation modal.
|
|
|
|
|
* This modal is shown if an action has a confirmation setting enabled.
|
|
|
|
|
* If they cancel, bail, dont show errors and dont run anything further
|
|
|
|
|
*/
|
|
|
|
|
export class UserCancelledActionExecutionError extends PluginActionExecutionError {
|
|
|
|
|
constructor() {
|
|
|
|
|
super("User cancelled action execution", true);
|
|
|
|
|
this.name = "UserCancelledActionExecutionError";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class TriggerEvaluationError extends Error {
|
|
|
|
|
constructor(message: string) {
|
|
|
|
|
super(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class UncaughtAppsmithPromiseError extends TriggerFailureError {
|
|
|
|
|
constructor(message: string, triggerMeta: TriggerMeta, error: Error) {
|
|
|
|
|
super(message, triggerMeta, error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-14 11:04:43 +00:00
|
|
|
|
|
|
|
|
export const getErrorAsString = (error: unknown): string => {
|
|
|
|
|
return isString(error) ? error : JSON.stringify(error);
|
|
|
|
|
};
|