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.
This commit is contained in:
dwindown
2025-11-20 00:54:52 +07:00
parent 72798b8a86
commit 4974d426ea

View File

@@ -92,8 +92,10 @@ class ProductsController {
* Get products list with filters * Get products list with filters
*/ */
public static function get_products(WP_REST_Request $request) { public static function get_products(WP_REST_Request $request) {
error_log('WooNooW ProductsController::get_products() CALLED'); error_log('WooNooW ProductsController::get_products() CALLED - START');
$page = max(1, (int) $request->get_param('page'));
try {
$page = max(1, (int) $request->get_param('page'));
$per_page = min(100, max(1, (int) ($request->get_param('per_page') ?: 20))); $per_page = min(100, max(1, (int) ($request->get_param('per_page') ?: 20)));
$search = $request->get_param('search'); $search = $request->get_param('search');
$status = $request->get_param('status'); $status = $request->get_param('status');
@@ -184,7 +186,14 @@ class ProductsController {
$response->header('Expires', '0'); $response->header('Expires', '0');
$response->header('X-WooNooW-Version', '2.0'); // Debug header $response->header('X-WooNooW-Version', '2.0'); // Debug header
error_log('WooNooW ProductsController::get_products() CALLED - END SUCCESS');
return $response; 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]);
}
} }
/** /**