diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index dabd64cc6c6ba..f672b9a8f3366 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -318,8 +318,8 @@ themes.Collection = Backbone.Collection.extend({ self.trigger( 'query:empty' ); } - }).fail( function() { - self.trigger( 'query:fail' ); + }).fail( function(response) { + self.trigger( 'query:fail', response); }); } else { // If it's a paginated request we need to fetch more themes... @@ -333,8 +333,8 @@ themes.Collection = Backbone.Collection.extend({ // We are done loading themes for now. self.loadingThemes = false; - }).fail( function() { - self.trigger( 'query:fail' ); + }).fail( function(response) { + self.trigger( 'query:fail', response); }); } @@ -1728,12 +1728,35 @@ themes.view.Installer = themes.view.Appearance.extend({ $( '.theme-browser' ).find( 'div.error' ).remove(); }); - this.listenTo( this.collection, 'query:fail', function() { + this.listenTo( this.collection, 'query:fail', function( response ) { + var $error = $( '
' ); + $( 'body' ).removeClass( 'loading-content' ); - $( '.theme-browser' ).find( 'div.error' ).remove(); - /* translators: %s: Support forums URL. */ - $( '.theme-browser' ).find( 'div.themes' ).before( '' + wp.i18n.sprintf( wp.i18n.__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), wp.i18n.__( 'https://wordpress.org/support/forums/' ) ) + '
' + + wp.i18n.sprintf( + /* translators: %s: Support forums URL. */ + wp.i18n.__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), + wp.i18n.__( 'https://wordpress.org/support/forums/' ) + ) + + '
' + ); + + if ( response && response.errorData ) { + $error.append( + $( '' ).append( + $( '' ).text( wp.i18n.__( 'Error details:' ) + ' ' ), + document.createTextNode( response.errorData ) + ) + ); + } + + $error.append( '' ); + + $( '.theme-browser' ).find( 'div.themes' ).before( $error ); + $( '.theme-browser .notice-error .try-again' ).on( 'click', function( e ) { e.preventDefault(); $( 'input.wp-filter-search' ).trigger( 'input' ); } ); diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 076549b218b82..e613103136f6c 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3640,7 +3640,16 @@ function wp_ajax_query_themes() { $api = themes_api( 'query_themes', $args ); if ( is_wp_error( $api ) ) { - wp_send_json_error(); + $error_data = $api->get_error_data(); + $response = array( + 'errorMessage' => $api->get_error_message(), + ); + + if ( is_string( $error_data ) && '' !== trim( $error_data ) ) { + $response['errorData'] = wp_strip_all_tags( $error_data ); + } + + wp_send_json_error( $response ); } $update_php = network_admin_url( 'update.php?action=install-theme' );