From 027920a696940a9a28967d167f67579f08c269ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miriam=20Trapero=20Rodr=C3=ADguez?= <90465230+Mimitrz@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:22:49 +0100 Subject: [PATCH 1/2] Themes: Display error details when theme API request fails. --- src/js/_enqueues/wp/theme.js | 41 ++++++++++++++++++++------ src/wp-admin/includes/ajax-actions.php | 11 ++++++- 2 files changed, 42 insertions(+), 10 deletions(-) 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' ); From d99eb895b4ea5e75742f1eeb7c5eb7ab3630a78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miriam=20Trapero=20Rodr=C3=ADguez?= <90465230+Mimitrz@users.noreply.github.com> Date: Thu, 26 Nov 2026 10:22:36 +0100 Subject: [PATCH 2/2] Themes: Handle HTTP and invalid JSON errors and remove unused errorMessage --- src/js/_enqueues/wp/theme.js | 15 ++++++++++++++- src/wp-admin/includes/ajax-actions.php | 4 +--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index f672b9a8f3366..306d411a7d3d7 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -1744,11 +1744,24 @@ themes.view.Installer = themes.view.Appearance.extend({ '' ); + var details = ''; + if ( response && response.errorData ) { + // Error payload sent by wp_ajax_query_themes(). + details = response.errorData; + } else if ( response && response.status && 200 !== response.status ) { + // HTTP-level failure, e.g. 500, 502, or 504. + details = response.status + ( response.statusText ? ' ' + response.statusText : '' ); + } else if ( response && response.responseText ) { + // A 200 response that could not be parsed as JSON. + details = wp.i18n.__( 'The server response was not valid JSON.' ); + } + + if ( details ) { $error.append( $( '' ).append( $( '' ).text( wp.i18n.__( 'Error details:' ) + ' ' ), - document.createTextNode( response.errorData ) + document.createTextNode( details ) ) ); } diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index e613103136f6c..96db2a805d1f6 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3641,9 +3641,7 @@ function wp_ajax_query_themes() { if ( is_wp_error( $api ) ) { $error_data = $api->get_error_data(); - $response = array( - 'errorMessage' => $api->get_error_message(), - ); + $response = array(); if ( is_string( $error_data ) && '' !== trim( $error_data ) ) { $response['errorData'] = wp_strip_all_tags( $error_data );