Skip to content

Commit 5c3c2e0

Browse files
authored
Some fixes (#17904)
1 parent fdb5d2f commit 5c3c2e0

File tree

3 files changed

+82
-15
lines changed

3 files changed

+82
-15
lines changed

packages/twenty-front/src/modules/object-record/record-field/hooks/useRecordsFieldVisibleGqlFields.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ export const useRecordsFieldVisibleGqlFields = ({
3737

3838
const allDepthOneGqlFields = generateDepthRecordGqlFieldsFromFields({
3939
objectMetadataItems,
40-
fields: visibleRecordFields.map(
41-
(field) =>
42-
fieldMetadataItemByFieldMetadataItemId[field.fieldMetadataItemId],
43-
),
40+
fields: visibleRecordFields
41+
.map(
42+
(field) =>
43+
fieldMetadataItemByFieldMetadataItemId[field.fieldMetadataItemId],
44+
)
45+
.filter(isDefined),
4446
depth: 1,
4547
isFilesFieldMigrated,
4648
});

packages/twenty-server/src/utils/__test__/get-domain-name-by-email.spec.ts

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,75 @@
1+
import {
2+
ErrorCode,
3+
UserInputError,
4+
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
15
import { getDomainNameByEmail } from 'src/utils/get-domain-name-by-email';
26

37
describe('getDomainNameByEmail', () => {
48
it('should return the domain name for a valid email', () => {
59
expect(getDomainNameByEmail('user@example.com')).toBe('example.com');
610
});
711

8-
it('should throw an error if email is empty', () => {
9-
expect(() => getDomainNameByEmail('')).toThrow('Email is required');
12+
it('should throw a UserInputError if email is empty', () => {
13+
expect(() => getDomainNameByEmail('')).toThrow(UserInputError);
14+
expect(() => getDomainNameByEmail('')).toThrow(
15+
'Email is required. Please provide a valid email address.',
16+
);
17+
18+
try {
19+
getDomainNameByEmail('');
20+
} catch (error) {
21+
expect(error).toBeInstanceOf(UserInputError);
22+
expect(error.extensions.code).toBe(ErrorCode.BAD_USER_INPUT);
23+
expect(error.extensions.userFriendlyMessage.message).toContain(
24+
'Email is required. Please provide a valid email address.',
25+
);
26+
}
1027
});
1128

12-
it('should throw an error if email does not contain "@"', () => {
29+
it('should throw a UserInputError if email does not contain "@"', () => {
1330
expect(() => getDomainNameByEmail('userexample.com')).toThrow(
14-
'Invalid email format',
31+
UserInputError,
1532
);
33+
34+
try {
35+
getDomainNameByEmail('userexample.com');
36+
} catch (error) {
37+
expect(error).toBeInstanceOf(UserInputError);
38+
expect(error.extensions.code).toBe(ErrorCode.BAD_USER_INPUT);
39+
expect(error.extensions.userFriendlyMessage.message).toContain(
40+
'The provided email address is not valid. Please use a standard email format (e.g., user@example.com).',
41+
);
42+
}
1643
});
1744

18-
it('should throw an error if email has more than one "@"', () => {
45+
it('should throw a UserInputError if email has more than one "@"', () => {
1946
expect(() => getDomainNameByEmail('user@example@com')).toThrow(
20-
'Invalid email format',
47+
UserInputError,
2148
);
49+
50+
try {
51+
getDomainNameByEmail('user@example@com');
52+
} catch (error) {
53+
expect(error).toBeInstanceOf(UserInputError);
54+
expect(error.extensions.code).toBe(ErrorCode.BAD_USER_INPUT);
55+
expect(error.extensions.userFriendlyMessage.message).toContain(
56+
'The provided email address is not valid. Please use a standard email format (e.g., user@example.com).',
57+
);
58+
}
2259
});
2360

24-
it('should throw an error if domain part is empty', () => {
25-
expect(() => getDomainNameByEmail('user@')).toThrow('Invalid email format');
61+
it('should throw a UserInputError if domain part is empty', () => {
62+
expect(() => getDomainNameByEmail('user@')).toThrow(UserInputError);
63+
64+
try {
65+
getDomainNameByEmail('user@');
66+
} catch (error) {
67+
expect(error).toBeInstanceOf(UserInputError);
68+
expect(error.extensions.code).toBe(ErrorCode.BAD_USER_INPUT);
69+
expect(error.extensions.userFriendlyMessage.message).toContain(
70+
'The provided email address is missing a domain. Please use a standard email format (e.g., user@example.com).',
71+
);
72+
}
2673
});
2774

2875
// Edge cases with weird but potentially valid email formats

packages/twenty-server/src/utils/get-domain-name-by-email.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1+
import { msg } from '@lingui/core/macro';
12
import { isNonEmptyString } from '@sniptt/guards';
23

4+
import { UserInputError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
5+
36
export const getDomainNameByEmail = (email: string) => {
47
if (!isNonEmptyString(email)) {
5-
throw new Error('Email is required');
8+
throw new UserInputError(
9+
'Email is required. Please provide a valid email address.',
10+
{
11+
userFriendlyMessage: msg`Email is required. Please provide a valid email address.`,
12+
},
13+
);
614
}
715

816
const fields = email.split('@');
917

1018
if (fields.length !== 2) {
11-
throw new Error(`Invalid email format (${fields.length - 1} @) ${email}`);
19+
throw new UserInputError(
20+
'The provided email address is not valid. Please use a standard email format (e.g., user@example.com).',
21+
{
22+
userFriendlyMessage: msg`The provided email address is not valid. Please use a standard email format (e.g., user@example.com).`,
23+
},
24+
);
1225
}
1326

1427
const domain = fields[1];
1528

1629
if (!domain) {
17-
throw new Error(`Invalid email format (no domain) ${email}`);
30+
throw new UserInputError(
31+
'The provided email address is missing a domain. Please use a standard email format (e.g., user@example.com).',
32+
{
33+
userFriendlyMessage: msg`The provided email address is missing a domain. Please use a standard email format (e.g., user@example.com).`,
34+
},
35+
);
1836
}
1937

2038
return domain;

0 commit comments

Comments
 (0)