1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import { I18n } from '@aws-amplify/core';
|
15 |
|
16 | export const MapEntries = [
|
17 | ['User does not exist', /user.*not.*exist/i],
|
18 | ['User already exists', /user.*already.*exist/i],
|
19 | ['Incorrect username or password', /incorrect.*username.*password/i],
|
20 | ['Invalid password format', /validation.*password/i],
|
21 | [
|
22 | 'Invalid phone number format',
|
23 | /invalid.*phone/i,
|
24 | 'Invalid phone number format. Please use a phone number format of +12345678900',
|
25 | ],
|
26 | ];
|
27 |
|
28 | export function AmplifyMessageMap(message) {
|
29 |
|
30 | const match = MapEntries.filter(entry => entry[1].test(message));
|
31 | if (match.length === 0) {
|
32 | return message;
|
33 | }
|
34 |
|
35 | const entry = match[0];
|
36 | const msg = entry.length > 2 ? entry[2] : entry[0];
|
37 |
|
38 | return I18n.get(entry[0], msg);
|
39 | }
|