Skip to content

Commit

Permalink
Changes the error Blaze shows during sync to be a warning (#39515)
Browse files Browse the repository at this point in the history
* Changes the error Blaze shows during sync to be a warning
  • Loading branch information
sbarbosa authored Oct 1, 2024
1 parent d4ab770 commit f34d1a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Changes the error Blaze shows during sync to be a warning
28 changes: 20 additions & 8 deletions projects/packages/blaze/src/class-dashboard-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,6 @@ public function get_blaze_posts( $req ) {
return array();
}

if ( ! $this->are_posts_ready() ) {
return new WP_Error( 'posts_not_ready', 'Posts are not synced yet.' );
}

// We don't use sub_path in the blaze posts, only query strings
if ( isset( $req['sub_path'] ) ) {
unset( $req['sub_path'] );
Expand All @@ -353,6 +349,24 @@ public function get_blaze_posts( $req ) {
$response['posts'] = $this->add_prices_in_posts( $response['posts'] );
}

$response = $this->add_warnings_to_posts_response( $response );

return $response;
}

/**
* Adds warning flags to the posts response.
*
* @param array $response The response object.
* @return array
*/
private function add_warnings_to_posts_response( $response ) {
if ( ! $this->are_posts_ready() && is_array( $response ) ) {
$response['warnings'] = array_merge(
array( 'sync_in_progress' ),
$response['warnings'] ?? array()
);
}
return $response;
}

Expand Down Expand Up @@ -392,10 +406,6 @@ public function get_dsp_blaze_posts( $req ) {
return array();
}

if ( ! $this->are_posts_ready() ) {
return new WP_Error( 'posts_not_ready', 'Posts are not synced yet.' );
}

// We don't use sub_path in the blaze posts, only query strings
if ( isset( $req['sub_path'] ) ) {
unset( $req['sub_path'] );
Expand All @@ -412,6 +422,8 @@ public function get_dsp_blaze_posts( $req ) {
$response['results'] = $this->add_prices_in_posts( $response['results'] );
}

$response = $this->add_warnings_to_posts_response( $response );

return $response;
}

Expand Down

0 comments on commit f34d1a7

Please sign in to comment.