From 4974d426ea43d87a9830054fa45ebcb38b88759e Mon Sep 17 00:00:00 2001 From: dwindown Date: Thu, 20 Nov 2025 00:54:52 +0700 Subject: [PATCH] debug: Add try-catch to get_products to catch silent errors Wrapped entire get_products() in try-catch. Will log: - START when function begins - END SUCCESS when completes - ERROR + stack trace if exception thrown This will reveal if there's a PHP error causing silent failure. --- includes/Api/ProductsController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index 74a530d..dbf7a20 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -92,8 +92,10 @@ class ProductsController { * Get products list with filters */ public static function get_products(WP_REST_Request $request) { - error_log('WooNooW ProductsController::get_products() CALLED'); - $page = max(1, (int) $request->get_param('page')); + error_log('WooNooW ProductsController::get_products() CALLED - START'); + + try { + $page = max(1, (int) $request->get_param('page')); $per_page = min(100, max(1, (int) ($request->get_param('per_page') ?: 20))); $search = $request->get_param('search'); $status = $request->get_param('status'); @@ -184,7 +186,14 @@ class ProductsController { $response->header('Expires', '0'); $response->header('X-WooNooW-Version', '2.0'); // Debug header + error_log('WooNooW ProductsController::get_products() CALLED - END SUCCESS'); return $response; + + } catch (\Exception $e) { + error_log('WooNooW ProductsController::get_products() ERROR: ' . $e->getMessage()); + error_log('WooNooW ProductsController::get_products() TRACE: ' . $e->getTraceAsString()); + return new WP_Error('products_error', $e->getMessage(), ['status' => 500]); + } } /**