Skip to content

Commit b9004dd

Browse files
committed
display white list of email domain
1 parent ef9d3ac commit b9004dd

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

helpers/errortypes.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ class ApiError extends Error {
44
field = 'general',
55
status = 400,
66
cause,
7+
data,
78
}) {
89
super(`${field}:${type}`);
910
this.type = type;
1011
this.field = field;
1112
this.status = status;
1213
this.cause = cause;
14+
this.data = data;
1315
}
1416

1517
toJSON() {
16-
return { type: this.type, field: this.field };
18+
const result = { type: this.type, field: this.field };
19+
if (this.data !== undefined) {
20+
result.data = this.data;
21+
}
22+
return result;
1723
}
1824
}
1925

routes/apiHandlers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ async function handleRequestEmailCode(ip, email, log, locale) {
917917
throw new ApiError({
918918
type: 'error_api_email_domain',
919919
field: 'email',
920+
data: { whiteEmailDomains },
920921
});
921922
}
922923

src/components/Form/Signup/UserInfo.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,22 @@ class UserInfo extends React.Component {
227227
}, 1000);
228228
})
229229
.catch(error => {
230+
let errorMessage = intl.formatMessage({ id: error.type });
231+
// If email domain error and contains allowed domain list, show domain list
232+
if (
233+
error.type === 'error_api_email_domain' &&
234+
error.data &&
235+
error.data.whiteEmailDomains &&
236+
Array.isArray(error.data.whiteEmailDomains) &&
237+
error.data.whiteEmailDomains.length > 0
238+
) {
239+
const domainsList = error.data.whiteEmailDomains.join(', ');
240+
errorMessage = `${errorMessage} (${domainsList})`;
241+
}
230242
this.props.form.setFields({
231243
email: {
232244
value: email,
233-
errors: [
234-
new Error(intl.formatMessage({ id: error.type })),
235-
],
245+
errors: [new Error(errorMessage)],
236246
},
237247
});
238248
window.email_code_count_seconds = 0;

src/utils/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default async function apiCall(path, payload, reqType = 'POST') {
3030
const error = new Error('ApiError');
3131
error.type = responseData.error.type;
3232
error.field = responseData.error.field;
33+
error.data = responseData.error.data;
3334
throw error;
3435
}
3536
return responseData;

0 commit comments

Comments
 (0)