Skip to content

Commit

Permalink
Boost: Fix ISA showing an error if no report was found (#40660)
Browse files Browse the repository at this point in the history
* Fix boost API client not properly parsing errors returned by wpcom

* Fix showing error when a report wasn't found

User might not have requested an analysis yet. That doesn't mean the UI
should show an error. This restores behavior from pre-Boost 3.6.0.

* Add changelogs

* Revert boost core changes

* remove changelog

* Revert "Revert boost core changes"

This reverts commit afa7179.

* Revert "remove changelog"

This reverts commit 870e13d.

* Clarify comment

---------

Co-authored-by: Adnan Haque <[email protected]>
  • Loading branch information
dilirity and haqadn authored Dec 20, 2024
1 parent fc13aac commit e564fe0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

General: Fixed not parsing error responses from WordPress.com properly.
23 changes: 19 additions & 4 deletions projects/packages/boost-core/src/lib/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,26 @@ public static function send_wpcom_request( $method, $endpoint, $args = null, $bo
$code
);

/*
* Normalize error responses from WordPress.com.
*
* When WordPress.com returns an error from Boost Cloud, the body contains
* statusCode and error. When it returns a WP_Error, it contains code and message.
*/
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$err_code = empty( $data['statusCode'] ) ? 'http_error' : $data['statusCode'];
$message = empty( $data['error'] ) ? $default_message : $data['error'];

return new \WP_Error( $err_code, $message );
if ( isset( $data['statusCode'] ) && isset( $data['error'] ) ) {
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$data_code = $data['statusCode'];
$data_message = $data['error'];
} elseif ( isset( $data['code'] ) && isset( $data['message'] ) ) {
$data_code = $data['code'];
$data_message = $data['message'];
}

$error_code = empty( $data_code ) ? 'http_error' : $data_code;
$message = empty( $data_message ) ? $default_message : $data_message;

return new \WP_Error( $error_code, $message );
}

return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const RecommendationsMeta: React.FC< Props > = ( { isCdnActive } ) => {
isaRequest.isError;

const getErrorMessage = ( report: typeof isaReport ) => {
if ( report?.status === 'error' || report?.status === 'not-found' ) {
if ( report?.status === 'error' ) {
return report.message;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

UI: Fixed showing an error if no ISA report was found.

0 comments on commit e564fe0

Please sign in to comment.