Update user friendly errors for translations (#15000)
Force msg typing instead of string for user friendly errors
This commit is contained in:
+24
-6
@@ -5,7 +5,10 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"error": {
|
||||
"code": "FIELD_METADATA_RELATION_MALFORMED",
|
||||
"message": "Morph relation creation payloads must have the same relation type",
|
||||
"userFriendlyMessage": "Morph relation creation payloads must have the same relation type",
|
||||
"userFriendlyMessage": {
|
||||
"id": Any<String>,
|
||||
"message": "Morph relation creation payloads must have the same relation type",
|
||||
},
|
||||
},
|
||||
"status": "fail",
|
||||
}
|
||||
@@ -16,7 +19,10 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"error": {
|
||||
"code": "FIELD_METADATA_RELATION_MALFORMED",
|
||||
"message": "Morph relation input transpilation failed",
|
||||
"userFriendlyMessage": "Invalid morph relation input",
|
||||
"userFriendlyMessage": {
|
||||
"id": Any<String>,
|
||||
"message": "Invalid morph relation input",
|
||||
},
|
||||
"value": [
|
||||
{
|
||||
"targetObjectMetadataId": Any<String>,
|
||||
@@ -33,7 +39,10 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"error": {
|
||||
"code": "FIELD_METADATA_RELATION_MALFORMED",
|
||||
"message": "Morph relation creation payloads must have only relation to the same object metadata",
|
||||
"userFriendlyMessage": "Morph relation creation payloads must only contain relation to the same object metadata",
|
||||
"userFriendlyMessage": {
|
||||
"id": Any<String>,
|
||||
"message": "Morph relation creation payloads must only contain relation to the same object metadata",
|
||||
},
|
||||
},
|
||||
"status": "fail",
|
||||
}
|
||||
@@ -44,7 +53,10 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"error": {
|
||||
"code": "FIELD_METADATA_RELATION_MALFORMED",
|
||||
"message": "Morph relation creation payloads are empty",
|
||||
"userFriendlyMessage": "At least one relation is require",
|
||||
"userFriendlyMessage": {
|
||||
"id": Any<String>,
|
||||
"message": "At least one relation is require",
|
||||
},
|
||||
},
|
||||
"status": "fail",
|
||||
}
|
||||
@@ -55,7 +67,10 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"error": {
|
||||
"code": "INVALID_FIELD_INPUT",
|
||||
"message": "Relation creation payload is required",
|
||||
"userFriendlyMessage": "Relation creation payload is required",
|
||||
"userFriendlyMessage": {
|
||||
"id": Any<String>,
|
||||
"message": "Relation creation payload is required",
|
||||
},
|
||||
"value": undefined,
|
||||
},
|
||||
"status": "fail",
|
||||
@@ -67,7 +82,10 @@ exports[`fromCreateFieldInputToFlatFieldMetadatasToCreate MORPH_RELATION test su
|
||||
"error": {
|
||||
"code": "FIELD_METADATA_RELATION_MALFORMED",
|
||||
"message": "Morph relation input transpilation failed",
|
||||
"userFriendlyMessage": "Invalid morph relation input",
|
||||
"userFriendlyMessage": {
|
||||
"id": Any<String>,
|
||||
"message": "Invalid morph relation input",
|
||||
},
|
||||
"value": [
|
||||
{
|
||||
"targetFieldIcon": "IconPet",
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined } from 'class-validator';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
@@ -66,7 +66,7 @@ export class FlatFieldMetadataTypeValidatorService {
|
||||
{
|
||||
code: FieldMetadataExceptionCode.UNCOVERED_FIELD_METADATA_TYPE_VALIDATION,
|
||||
message: 'Morph relation feature flag is disabled',
|
||||
userFriendlyMessage: t`Morph relation fields are disabled for your workspace`,
|
||||
userFriendlyMessage: msg`Morph relation fields are disabled for your workspace`,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -192,7 +192,7 @@ export class FlatFieldMetadataTypeValidatorService {
|
||||
code: FieldMetadataExceptionCode.UNCOVERED_FIELD_METADATA_TYPE_VALIDATION,
|
||||
message: `Unsupported field metadata type ${fieldType}`,
|
||||
value: fieldType,
|
||||
userFriendlyMessage: t`Unsupported field metadata type ${fieldType}`,
|
||||
userFriendlyMessage: msg`Unsupported field metadata type ${fieldType}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
import { type MessageDescriptor } from '@lingui/core';
|
||||
|
||||
import { type FieldMetadataExceptionCode } from 'src/engine/metadata-modules/field-metadata/field-metadata.exception';
|
||||
|
||||
export type FlatFieldMetadataValidationError = {
|
||||
code: FieldMetadataExceptionCode;
|
||||
message: string;
|
||||
userFriendlyMessage?: string;
|
||||
userFriendlyMessage?: MessageDescriptor;
|
||||
value?: unknown;
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import {
|
||||
assertUnreachable,
|
||||
@@ -59,7 +59,7 @@ export const fromCreateFieldInputToFlatFieldMetadatasToCreate = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.OBJECT_METADATA_NOT_FOUND,
|
||||
message: 'Provided object metadata id does not exist',
|
||||
userFriendlyMessage: t`Created field metadata, parent object metadata not found`,
|
||||
userFriendlyMessage: msg`Created field metadata, parent object metadata not found`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { type FieldMetadataType } from 'twenty-shared/types';
|
||||
import { computeMorphRelationFieldName, isDefined } from 'twenty-shared/utils';
|
||||
import { v4 } from 'uuid';
|
||||
@@ -45,7 +45,7 @@ export const fromMorphRelationCreateFieldInputToFlatFieldMetadatas = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: `Relation creation payload is required`,
|
||||
userFriendlyMessage: t`Relation creation payload is required`,
|
||||
userFriendlyMessage: msg`Relation creation payload is required`,
|
||||
value: rawMorphCreationPayload,
|
||||
},
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { type FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
@@ -38,7 +38,7 @@ export const fromRelationCreateFieldInputToFlatFieldMetadatas = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: `Relation creation payload is required`,
|
||||
userFriendlyMessage: t`Relation creation payload is required`,
|
||||
userFriendlyMessage: msg`Relation creation payload is required`,
|
||||
value: rawCreationPayload,
|
||||
},
|
||||
};
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import {
|
||||
extractAndSanitizeObjectStringFields,
|
||||
isDefined,
|
||||
@@ -150,7 +150,7 @@ export const fromUpdateFieldInputToFlatFieldMetadata = ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_NOT_FOUND,
|
||||
message: 'Field metadata to update not found',
|
||||
userFriendlyMessage: t`Field metadata to update not found`,
|
||||
userFriendlyMessage: msg`Field metadata to update not found`,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -172,7 +172,7 @@ export const fromUpdateFieldInputToFlatFieldMetadata = ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: `Cannot update standard field metadata properties: ${invalidProperties}`,
|
||||
userFriendlyMessage: t`Cannot update standard field properties: ${invalidProperties}`,
|
||||
userFriendlyMessage: msg`Cannot update standard field properties: ${invalidProperties}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+7
-7
@@ -53,7 +53,7 @@ const validateMetadataOptionLabel = (
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: t`Option label is required`,
|
||||
userFriendlyMessage: t`Option label is required`,
|
||||
userFriendlyMessage: msg`Option label is required`,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -63,7 +63,7 @@ const validateMetadataOptionLabel = (
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: t`Option label must be a string of at least one character`,
|
||||
userFriendlyMessage: t`Option label format not supported`,
|
||||
userFriendlyMessage: msg`Option label format not supported`,
|
||||
value: sanitizedLabel,
|
||||
},
|
||||
];
|
||||
@@ -102,7 +102,7 @@ const validateMetadataOptionValue = (
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: t`Option value is required`,
|
||||
userFriendlyMessage: t`Option value is required`,
|
||||
userFriendlyMessage: msg`Option value is required`,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -112,7 +112,7 @@ const validateMetadataOptionValue = (
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: t`Option value must be a string of at least one character`,
|
||||
userFriendlyMessage: t`Option value format not supported`,
|
||||
userFriendlyMessage: msg`Option value format not supported`,
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -175,7 +175,7 @@ const validateFieldMetadataInputOptions = <T extends EnumFieldMetadataType>(
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: 'Options are required for enum fields',
|
||||
userFriendlyMessage: t`Options are required for enum fields`,
|
||||
userFriendlyMessage: msg`Options are required for enum fields`,
|
||||
value: options,
|
||||
},
|
||||
];
|
||||
@@ -206,7 +206,7 @@ const validateSelectDefaultValue = ({
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: `Default value for select must be a string got ${defaultValue}`,
|
||||
userFriendlyMessage: t`Default value must be a string`,
|
||||
userFriendlyMessage: msg`Default value must be a string`,
|
||||
value: defaultValue,
|
||||
},
|
||||
];
|
||||
@@ -243,7 +243,7 @@ const validateMultiSelectDefaultValue = ({
|
||||
return [
|
||||
{
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
userFriendlyMessage: t`Multi-select field default value must be an array`,
|
||||
userFriendlyMessage: msg`Multi-select field default value must be an array`,
|
||||
message: `Default value for multi-select must be an array got ${multiSelectDefaultValue}`,
|
||||
value: multiSelectDefaultValue,
|
||||
},
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
@@ -101,7 +101,7 @@ export const validateFlatFieldMetadataNameAvailability = ({
|
||||
code: FieldMetadataExceptionCode.NOT_AVAILABLE,
|
||||
value: flatFieldMetadataName,
|
||||
message: `Name "${flatFieldMetadataName}" is not available as it is already used by another field`,
|
||||
userFriendlyMessage: t`Name "${flatFieldMetadataName}" is not available as it is already used by another field`,
|
||||
userFriendlyMessage: msg`Name "${flatFieldMetadataName}" is not available as it is already used by another field`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export const validateFlatFieldMetadataNameAvailability = ({
|
||||
code: FieldMetadataExceptionCode.RESERVED_KEYWORD,
|
||||
message: `Name "${flatFieldMetadataName}" is reserved composite field name`,
|
||||
value: flatFieldMetadataName,
|
||||
userFriendlyMessage: t`Name "${flatFieldMetadataName}" is not available`,
|
||||
userFriendlyMessage: msg`Name "${flatFieldMetadataName}" is not available`,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,5 +1,3 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { FieldMetadataExceptionCode } from 'src/engine/metadata-modules/field-metadata/field-metadata.exception';
|
||||
import { type FlatFieldMetadataValidationError } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata-validation-error.type';
|
||||
import { METADATA_NAME_VALIDATORS } from 'src/engine/metadata-modules/utils/constants/metadata-name-flat-metadata-validators.constants';
|
||||
@@ -13,8 +11,8 @@ export const validateFlatFieldMetadataName = (
|
||||
if (isInvalid) {
|
||||
return {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: t(message),
|
||||
userFriendlyMessage: t(message),
|
||||
message: message.message ?? '',
|
||||
userFriendlyMessage: message,
|
||||
value: name,
|
||||
};
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined, isValidUuid } from 'twenty-shared/utils';
|
||||
|
||||
import { FieldMetadataExceptionCode } from 'src/engine/metadata-modules/field-metadata/field-metadata.exception';
|
||||
@@ -26,7 +26,7 @@ export const validateMorphOrRelationFlatFieldMetadata = async ({
|
||||
: {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: `Invalid uuid ${id}`,
|
||||
userFriendlyMessage: t`Invalid uuid ${id}`,
|
||||
userFriendlyMessage: msg`Invalid uuid ${id}`,
|
||||
value: id,
|
||||
},
|
||||
);
|
||||
@@ -44,7 +44,7 @@ export const validateMorphOrRelationFlatFieldMetadata = async ({
|
||||
errors.push({
|
||||
code: FieldMetadataExceptionCode.OBJECT_METADATA_NOT_FOUND,
|
||||
message: 'Relation target object metadata not found',
|
||||
userFriendlyMessage: t`Object targeted by the relation not found`,
|
||||
userFriendlyMessage: msg`Object targeted by the relation not found`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export const validateMorphOrRelationFlatFieldMetadata = async ({
|
||||
message: isDefined(remainingFlatEntityMapsToValidate)
|
||||
? 'Relation field target metadata not found in both existing and about to be created field metadatas'
|
||||
: 'Relation field target metadata not found',
|
||||
userFriendlyMessage: t`Relation field target metadata not found`,
|
||||
userFriendlyMessage: msg`Relation field target metadata not found`,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined } from 'class-validator';
|
||||
import { type RelationCreationPayload } from 'twenty-shared/types';
|
||||
|
||||
@@ -35,7 +35,7 @@ export const validateMorphRelationCreationPayload = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message: 'Morph relation creation payloads are empty',
|
||||
userFriendlyMessage: t`At least one relation is require`,
|
||||
userFriendlyMessage: msg`At least one relation is require`,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -55,7 +55,7 @@ export const validateMorphRelationCreationPayload = async ({
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message:
|
||||
'Morph relation creation payloads must have the same relation type',
|
||||
userFriendlyMessage: t`Morph relation creation payloads must have the same relation type`,
|
||||
userFriendlyMessage: msg`Morph relation creation payloads must have the same relation type`,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -74,7 +74,7 @@ export const validateMorphRelationCreationPayload = async ({
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message:
|
||||
'Morph relation creation payloads must not target source object metadata',
|
||||
userFriendlyMessage: t`Morph relation creation payloads must only contain relation to other object metadata`,
|
||||
userFriendlyMessage: msg`Morph relation creation payloads must only contain relation to other object metadata`,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -88,7 +88,7 @@ export const validateMorphRelationCreationPayload = async ({
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message:
|
||||
'Morph relation creation payloads must have only relation to the same object metadata',
|
||||
userFriendlyMessage: t`Morph relation creation payloads must only contain relation to the same object metadata`,
|
||||
userFriendlyMessage: msg`Morph relation creation payloads must only contain relation to the same object metadata`,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -130,7 +130,7 @@ export const validateMorphRelationCreationPayload = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message: 'Morph relation input transpilation failed',
|
||||
userFriendlyMessage: t`Invalid morph relation input`,
|
||||
userFriendlyMessage: msg`Invalid morph relation input`,
|
||||
value: relationCreationPayloadReport.failed
|
||||
.map((failedTranspilation) => failedTranspilation.error.value)
|
||||
.filter(isDefined),
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { type RelationCreationPayload } from 'twenty-shared/types';
|
||||
import {
|
||||
isDefined,
|
||||
@@ -42,7 +42,7 @@ export const validateRelationCreationPayload = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message: `Relation creation payload is invalid`,
|
||||
userFriendlyMessage: t`Invalid relation creation payload`,
|
||||
userFriendlyMessage: msg`Invalid relation creation payload`,
|
||||
value: relationCreationPayload,
|
||||
},
|
||||
};
|
||||
@@ -62,7 +62,7 @@ export const validateRelationCreationPayload = async ({
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message: `Object metadata relation target not found for relation creation payload`,
|
||||
userFriendlyMessage: t`Object targeted by field to create not found`,
|
||||
userFriendlyMessage: msg`Object targeted by field to create not found`,
|
||||
value: relationCreationPayload,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user