Skip to content

Commit

Permalink
Fix Uncaught TypeError in JavaScript
Browse files Browse the repository at this point in the history
By making sure we check results[i].error is defined befor attempting
to access its length, which results in:

> Uncaught TypeError: Cannot read property 'length' of undefined

When it is undefined.
  • Loading branch information
thenbrent authored and Brent Shepherd committed Jul 26, 2018
1 parent d3bac5a commit e2d61ac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions assets/js/wcs-importer.js
Expand Up @@ -102,8 +102,10 @@ jQuery(document).ready(function ($) {
}
} else {
table_data += '<td class="row error-import">' + wcsi_data.failed + '</td>';
for (x = 0; x < results[i].error.length; x += 1) {
error_string += '<br>' + (x + 1) + '. ' + results[i].error[x];
if (typeof results[i].error !== 'undefined') {
for (x = 0; x < results[i].error.length; x += 1) {
error_string += '<br>' + (x + 1) + '. ' + results[i].error[x];
}
}

table_data += '<td colspan="5">' + wcsi_data.error_string + '</td>';
Expand Down

0 comments on commit e2d61ac

Please sign in to comment.