diff --git a/js/plugin-report.js b/js/plugin-report.js index d4f517f..36a106b 100644 --- a/js/plugin-report.js +++ b/js/plugin-report.js @@ -54,15 +54,28 @@ jQuery(document).ready( function( $ ){ }; jQuery.post( ajaxurl, data, function(response) { - // parse the response - const obj = JSON.parse(response); - // replace the temporary table row with the new data - $('#plugin-report-table .plugin-report-row-temp-' + slug ).replaceWith( obj.html ); - // on to the next... + try { + const obj = JSON.parse(response); + $('#plugin-report-table .plugin-report-row-temp-' + slug ).replaceWith( obj.html ); + } catch (e) { + rtpr_replace_with_error( slug ); + } + rtpr_process_next_plugin(); + }).fail( function() { + rtpr_replace_with_error( slug ); rtpr_process_next_plugin(); }); } + + function rtpr_replace_with_error( slug ){ + const cols = plugin_report_vars.cols_per_row || 9; + const msg = plugin_report_vars.ajax_error || 'Error'; + $('#plugin-report-table .plugin-report-row-temp-' + slug ).replaceWith( + '' + msg + '' + ); + } + // kick things off rtpr_process_next_plugin(); diff --git a/rt-plugin-report.php b/rt-plugin-report.php index 6b76f78..5b524a3 100644 --- a/rt-plugin-report.php +++ b/rt-plugin-report.php @@ -190,6 +190,8 @@ public function enqueue_assets( $hook ) { 'export_btn' => __( 'Export .csv file', 'plugin-report' ), 'plugin_url_header' => __( 'Plugin URL', 'plugin-report' ), 'author_url_header' => __( 'Author URL', 'plugin-report' ), + 'ajax_error' => __( 'Error fetching plugin info.', 'plugin-report' ), + 'cols_per_row' => self::COLS_PER_ROW, ); wp_localize_script( 'plugin-report-js', 'plugin_report_vars', $vars ); // Enqueue admin CSS file.