Define server error messages to display in FE from the server (#12973)
Currently, when a server query or mutation from the front-end fails, the error message defined server-side is displayed in a snackbar in the front-end. These error messages usually contain technical details that don't belong to the user interface, such as "ObjectMetadataCollection not found" or "invalid ENUM value for ...". **BE** In addition to the original error message that is still needed (for the request response, debugging, sentry monitoring etc.), we add a `displayedErrorMessage` that will be used in the snackbars. It's only relevant to add it for the messages that will reach the FE (ie. not in jobs or in rest api for instance) and if it can help the user sort out / fix things (ie. we do add displayedErrorMessage for "Cannot create multiple draft versions for the same workflow" or "Cannot delete [field], please update the label identifier field first", but not "Object metadata does not exist"), even if in practice in the FE users should not be able to perform an action that will not work (ie should not be able to save creation of multiple draft versions of the same workflows). **FE** To ease the usage we replaced enqueueSnackBar with enqueueErrorSnackBar and enqueueSuccessSnackBar with an api that only requires to pass on the error. If no displayedErrorMessage is specified then the default error message is `An error occured.`
This commit is contained in:
+6
-2
@@ -1,8 +1,12 @@
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export class WorkflowQueryValidationException extends CustomException {
|
||||
constructor(message: string, code: WorkflowQueryValidationExceptionCode) {
|
||||
super(message, code);
|
||||
constructor(
|
||||
message: string,
|
||||
code: WorkflowQueryValidationExceptionCode,
|
||||
{ userFriendlyMessage }: { userFriendlyMessage?: string } = {},
|
||||
) {
|
||||
super(message, code, userFriendlyMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -1,8 +1,12 @@
|
||||
import { CustomException } from 'src/utils/custom-exception';
|
||||
|
||||
export class WorkflowVersionStepException extends CustomException {
|
||||
constructor(message: string, code: WorkflowVersionStepExceptionCode) {
|
||||
super(message, code);
|
||||
constructor(
|
||||
message: string,
|
||||
code: WorkflowVersionStepExceptionCode,
|
||||
{ userFriendlyMessage }: { userFriendlyMessage?: string } = {},
|
||||
) {
|
||||
super(message, code, userFriendlyMessage);
|
||||
}
|
||||
}
|
||||
export enum WorkflowVersionStepExceptionCode {
|
||||
|
||||
+5
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import {
|
||||
WorkflowQueryValidationException,
|
||||
WorkflowQueryValidationExceptionCode,
|
||||
@@ -11,6 +13,9 @@ export const assertWorkflowStatusesNotSet = (
|
||||
throw new WorkflowQueryValidationException(
|
||||
'Statuses cannot be set manually.',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
{
|
||||
userFriendlyMessage: t`Statuses cannot be set manually.`,
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
+5
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
||||
import {
|
||||
@@ -14,6 +16,9 @@ export function assertWorkflowVersionHasSteps(
|
||||
throw new WorkflowTriggerException(
|
||||
'Workflow version does not contain at least one step',
|
||||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
|
||||
{
|
||||
userFriendlyMessage: t`Workflow version does not contain at least one step`,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import {
|
||||
WorkflowQueryValidationException,
|
||||
WorkflowQueryValidationExceptionCode,
|
||||
@@ -14,6 +16,9 @@ export const assertWorkflowVersionIsDraft = (
|
||||
throw new WorkflowQueryValidationException(
|
||||
'Workflow version is not in draft status',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
{
|
||||
userFriendlyMessage: t`Workflow version is not in draft status`,
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
+5
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import {
|
||||
WorkflowTriggerException,
|
||||
@@ -17,6 +19,9 @@ export function assertWorkflowVersionTriggerIsDefined(
|
||||
throw new WorkflowTriggerException(
|
||||
'Workflow version does not contain trigger',
|
||||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
|
||||
{
|
||||
userFriendlyMessage: t`Workflow version does not contain trigger`,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { IsNull, Not } from 'typeorm';
|
||||
|
||||
import {
|
||||
@@ -38,6 +39,9 @@ export class WorkflowVersionValidationWorkspaceService {
|
||||
throw new WorkflowQueryValidationException(
|
||||
'Cannot create workflow version with status other than draft',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
{
|
||||
userFriendlyMessage: t`Cannot create workflow version with status other than draft`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,6 +66,9 @@ export class WorkflowVersionValidationWorkspaceService {
|
||||
throw new WorkflowQueryValidationException(
|
||||
'Cannot create multiple draft versions for the same workflow',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
{
|
||||
userFriendlyMessage: t`Cannot create multiple draft versions for the same workflow`,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -89,6 +96,9 @@ export class WorkflowVersionValidationWorkspaceService {
|
||||
throw new WorkflowQueryValidationException(
|
||||
'Cannot update workflow version status manually',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
{
|
||||
userFriendlyMessage: t`Cannot update workflow version status manually`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,6 +142,9 @@ export class WorkflowVersionValidationWorkspaceService {
|
||||
throw new WorkflowQueryValidationException(
|
||||
'The initial version of a workflow can not be deleted',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
{
|
||||
userFriendlyMessage: t`The initial version of a workflow can not be deleted`,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user