From 4a1148fc2ca52675cff50991c14a1b863dafe21c Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Mon, 16 Oct 2023 19:45:09 +0530 Subject: [PATCH] fix: return error response on error --- .../woocommerce-utils/woocommerce-utils.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/e2e/test-plugins/woocommerce-utils/woocommerce-utils.php b/tests/e2e/test-plugins/woocommerce-utils/woocommerce-utils.php index 05407b9..6f948bf 100644 --- a/tests/e2e/test-plugins/woocommerce-utils/woocommerce-utils.php +++ b/tests/e2e/test-plugins/woocommerce-utils/woocommerce-utils.php @@ -16,7 +16,11 @@ 'methods' => 'DELETE', 'permission_callback' => '__return_true', 'callback' => function () { - WC_Log_Handler_File::delete_logs_before_timestamp( strtotime( '+2 day' ) ); + try { + WC_Log_Handler_File::delete_logs_before_timestamp( strtotime( '+2 day' ) ); + } catch ( Exception $e ) { + return new WP_REST_Response( false, 500 ); + } return new WP_REST_Response( true, 200 ); }, @@ -27,7 +31,12 @@ 'methods' => 'DELETE', 'callback' => function () { global $wpdb; - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}email_log" ); + + try { + $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}email_log" ); + } catch ( Exception $e ) { + return new WP_REST_Response( false, 500 ); + } return new WP_REST_Response( true, 200 ); },