diff --git a/assets/js/src/wizard/woocommerce_import_controller.jsx b/assets/js/src/wizard/woocommerce_import_controller.jsx
index 7f74384dd8..7183589f94 100644
--- a/assets/js/src/wizard/woocommerce_import_controller.jsx
+++ b/assets/js/src/wizard/woocommerce_import_controller.jsx
@@ -25,15 +25,7 @@ class WooCommerceImportController extends React.Component {
endpoint: 'settings',
action: 'set',
data,
- }).fail((response) => {
- this.setState({ loading: false });
- if (response.errors.length > 0) {
- MailPoet.Notice.error(
- response.errors.map(error => error.message),
- { scroll: true }
- );
- }
- });
+ }).fail(this.handleApiError);
}
scheduleImport() {
@@ -41,15 +33,16 @@ class WooCommerceImportController extends React.Component {
api_version: window.mailpoet_api_version,
endpoint: 'importExport',
action: 'setupWooCommerceInitialImport',
- }).then(() => this.setState({ loading: false })).fail((response) => {
- this.setState({ loading: false });
- if (response.errors.length > 0) {
- MailPoet.Notice.error(
- response.errors.map(error => error.message),
- { scroll: true }
- );
- }
- });
+ }).then(() => this.setState({ loading: false })).fail(this.handleApiError);
+ }
+
+ handleApiError(response) {
+ this.setState({ loading: false });
+ let errorMessage = MailPoet.I18n.t('unknownError');
+ if (response && response.errors && response.errors.length > 0) {
+ errorMessage = response.errors.map(error => error.message);
+ }
+ MailPoet.Notice.error(errorMessage, { scroll: true });
}
submit(importType) {
diff --git a/views/woocommerce_list_import.html b/views/woocommerce_list_import.html
index d9cc5274d5..d13ac800a6 100644
--- a/views/woocommerce_list_import.html
+++ b/views/woocommerce_list_import.html
@@ -20,5 +20,6 @@
'wooCommerceListImportCheckboxUnsubscribed': __('add all my customers to the list, but as unsubscribed. They can join this list next time they check out'),
'wooCommerceListImportInfo4': __('Their subscription preference on other lists won’t be changed.'),
'wooCommerceListImportSubmit': _x('Create my WooCommerce Customers list now!', 'Submit button caption'),
+'unknownError': __('Unknown error'),
}) %>
<% endblock %>