From 3d387a5434dd0f74eaa5434232d1d805956865e3 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Tue, 10 Dec 2024 18:29:26 +0530 Subject: [PATCH] Better be safe --- projects/packages/publicize/src/class-connections.php | 2 +- .../src/rest-endpoints/class-connections-controller.php | 5 +++-- .../src/rest-endpoints/class-services-controller.php | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/projects/packages/publicize/src/class-connections.php b/projects/packages/publicize/src/class-connections.php index 69fcce0f90299..eb9215598a1ed 100644 --- a/projects/packages/publicize/src/class-connections.php +++ b/projects/packages/publicize/src/class-connections.php @@ -91,7 +91,7 @@ public static function fetch_connections( $run_tests = false ) { $response = Client::wpcom_json_api_request_as_user( $path, '3', array(), null, 'wpcom' ); - if ( is_wp_error( $response ) ) { + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { // TODO log error. return array(); } diff --git a/projects/packages/publicize/src/rest-endpoints/class-connections-controller.php b/projects/packages/publicize/src/rest-endpoints/class-connections-controller.php index 0f347013968e9..b198b539aef5a 100644 --- a/projects/packages/publicize/src/rest-endpoints/class-connections-controller.php +++ b/projects/packages/publicize/src/rest-endpoints/class-connections-controller.php @@ -208,8 +208,9 @@ public function get_items( $request ) { $response = Client::wpcom_json_api_request_as_user( $path, 'v3', array( 'method' => 'GET' ) ); - if ( is_wp_error( $response ) ) { - return rest_ensure_response( $response ); + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + // TODO log error. + return rest_ensure_response( array() ); } return rest_ensure_response( diff --git a/projects/packages/publicize/src/rest-endpoints/class-services-controller.php b/projects/packages/publicize/src/rest-endpoints/class-services-controller.php index e6d08b3010b67..ad366f0ec89ec 100644 --- a/projects/packages/publicize/src/rest-endpoints/class-services-controller.php +++ b/projects/packages/publicize/src/rest-endpoints/class-services-controller.php @@ -144,8 +144,9 @@ public function get_items( $request ) { $response = Client::wpcom_json_api_request_as_user( $path, 'v3', array( 'method' => 'GET' ) ); - if ( is_wp_error( $response ) ) { - return rest_ensure_response( $response ); + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + // TODO log error. + return rest_ensure_response( array() ); } return rest_ensure_response(