From 0b0ac3c1cd30c8248b1fa5e592004eaf051f4c08 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 4 Jun 2024 21:09:33 +0530 Subject: [PATCH 1/2] Improve Error Handling for FacebookConnectButton --- includes/RestApi/FacebookController.php | 14 +++++++------- src/components/facebookConnectButton.js | 2 -- src/utils/helper.js | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/includes/RestApi/FacebookController.php b/includes/RestApi/FacebookController.php index 107afc9..9d7330f 100644 --- a/includes/RestApi/FacebookController.php +++ b/includes/RestApi/FacebookController.php @@ -110,13 +110,13 @@ public function get_fb_details() ); } if ( is_string( $fb_details ) && preg_match( '/^token not found!$/', $fb_details ) ) { - return new \WP_REST_Response( - array( - 'status' => 'error', - 'details' => 'You are not authorized' - ), - 401 - ); + return new \WP_Error( + 'nfd_module_facebook_error', + __( 'Token not found.', 'wp-module-facebook' ), + array( + 'status' => 404, + ), + ); } else { return new \WP_REST_Response( diff --git a/src/components/facebookConnectButton.js b/src/components/facebookConnectButton.js index 176b190..619e734 100644 --- a/src/components/facebookConnectButton.js +++ b/src/components/facebookConnectButton.js @@ -54,7 +54,6 @@ const FacebookConnectButton = ({ if (typeof onFailure === 'function') { onFailure(err); } - console.error(err); }); setFieldValue(res.token); }) @@ -63,7 +62,6 @@ const FacebookConnectButton = ({ if (typeof onFailure === 'function') { onFailure(err); } - console.error(err); }); const getProfileData = () => { diff --git a/src/utils/helper.js b/src/utils/helper.js index 04e6963..df6e74b 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -41,7 +41,7 @@ export const getFacebookUserProfileDetails = () => { return res?.details; }) .catch((error) => { - throw { message: 'failed to load the data', errorMsg: error }; + throw error; }); }; From e362b628d7d2d21113997b146442c2372f1da700 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Wed, 5 Jun 2024 12:45:38 +0530 Subject: [PATCH 2/2] Change message --- includes/RestApi/FacebookController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/RestApi/FacebookController.php b/includes/RestApi/FacebookController.php index 9d7330f..1b188a2 100644 --- a/includes/RestApi/FacebookController.php +++ b/includes/RestApi/FacebookController.php @@ -112,7 +112,7 @@ public function get_fb_details() if ( is_string( $fb_details ) && preg_match( '/^token not found!$/', $fb_details ) ) { return new \WP_Error( 'nfd_module_facebook_error', - __( 'Token not found.', 'wp-module-facebook' ), + __( 'Details not found.', 'wp-module-facebook' ), array( 'status' => 404, ),